What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » MySQL Date/time help?

MySQL Date/time help?
Author: Message:
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
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.
01-07-2010 12:03 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
MySQL Date/time help? - by Jimbo on 01-06-2010 at 05:33 PM
RE: MySQL Date/time help? - by absorbation on 01-06-2010 at 06:15 PM
RE: MySQL Date/time help? - by Jimbo on 01-06-2010 at 06:51 PM
RE: MySQL Date/time help? - by absorbation on 01-06-2010 at 07:10 PM
RE: MySQL Date/time help? - by Spunky on 01-06-2010 at 07:20 PM
RE: MySQL Date/time help? - by Lou on 01-06-2010 at 07:35 PM
RE: MySQL Date/time help? - by Spunky on 01-06-2010 at 07:42 PM
RE: MySQL Date/time help? - by Jimbo on 01-06-2010 at 08:14 PM
RE: MySQL Date/time help? - by Adeptus on 01-07-2010 at 12:03 AM
RE: MySQL Date/time help? - by Jimbo on 01-07-2010 at 01:42 PM
RE: MySQL Date/time help? - by Adeptus on 01-07-2010 at 03:51 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On