Presto-X Posted September 15, 2008 Share Posted September 15, 2008 Hello everyone, I have a large database with a list of dates, the system preformats the dates and saves them in this format 01/05/2009. but when I use mysql to sort by date it is not turning out like I want. This is how my dates are getting displayed: 01/05/2009 03/24/2009 09/15/2008 10/15/2008 11/03/2008 This is the line I'm using: $query_upcourses = "SELECT * FROM jos_courses_dates ORDER BY course_start_date ASC"; If you need any other information let me know. Link to comment https://forums.phpfreaks.com/topic/124283-solved-help-with-sorting-by-dates-formated-like-01052009/ Share on other sites More sharing options...
Mchl Posted September 15, 2008 Share Posted September 15, 2008 Store your dates as DATE, DATETIME or TIMESTAMP and not as strings. Will help a lot. Link to comment https://forums.phpfreaks.com/topic/124283-solved-help-with-sorting-by-dates-formated-like-01052009/#findComment-641784 Share on other sites More sharing options...
Presto-X Posted September 15, 2008 Author Share Posted September 15, 2008 Thanks for the reply Mchl, I updated my date rows from varchar to date. I'm using a javascript date selector, found here: http://www.dynamicdrive.com/dynamicindex7/jasoncalendar.htm they give you the following date formats, what format should I use when saving to my database? YYYYMMDD YYYY-MM-DD * YYYY-DD-MM * YYYY/MM/DD * YYYY/DD/MM * YYYY-DD-MON * ** YYYY-MON-DD * ** MM-DD-YYYY * DD-MM-YYYY * MM/DD/YYYY * DD/MM/YYYY * DD-MON-YYYY * ** MON-DD-YYYY * ** Link to comment https://forums.phpfreaks.com/topic/124283-solved-help-with-sorting-by-dates-formated-like-01052009/#findComment-642253 Share on other sites More sharing options...
Mchl Posted September 15, 2008 Share Posted September 15, 2008 Any one that fits you. Using PHP functions date can be transformed to a format that will be acceptable by mySQL (YYYY-MM-DD) Link to comment https://forums.phpfreaks.com/topic/124283-solved-help-with-sorting-by-dates-formated-like-01052009/#findComment-642260 Share on other sites More sharing options...
Presto-X Posted September 15, 2008 Author Share Posted September 15, 2008 sweet, thanks for the help, I used YYYYMMDD and the javascript and mysql seem to both like that format, so I'm going to brush back up on date formating. Link to comment https://forums.phpfreaks.com/topic/124283-solved-help-with-sorting-by-dates-formated-like-01052009/#findComment-642271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.