RE: MySQL Date/time help?
Without making any changes to how you are storing your data, the easiest solution would be to use:
SELECT * FROM myTable ORDER BY STR_TO_DATE(myTimestamp, '%m/%d/%y %H:%i:%s') DESC
That should do exactly what you want, by converting your date/time string to a DATETIME value for sorting on the fly. I doubt your tables are large enough for this to be a performance concern.
The best practice would be to redesign the table to use DATETIME for the timestamp. You can use the STR_TO_DATE() function with the above format string to convert the data as you insert it.
Relying on an incrementing ID for this is a kludge, a logic flaw, and asking for it to bite you in the posterior. You shouldn't rely on the assumption that your data will always be inserted in chronological order, even if you believe it will be -- that is exactly the kind of assumption that leads to hard to find bugs down the road.
|