?
Solved

How to properly order dates in a record set

Posted on 2010-09-07
3
Medium Priority
?
301 Views
Last Modified: 2013-12-13
I am trying to properly list some dates. Dates are just entered as normal charters into the database in the following format: 9/14/2010, 10/14/2010 and 2/5/2011. This code works: $query_Recordset4 = "SELECT * FROM ScheduledClasses WHERE ClassTypeName='Gun Safety' ORDER BY ClassDate ASC"; but the order displayed goes 2/5/2011, then 9/14/2010, then 10/14/2010. I need it to go in the correct order of 9/14/2010, then 10/14/2010, then 2/5/2011.

I'm new at this so any help would be appreciated.


Thanks!
0
Comment
Question by:Sunfish2203
3 Comments
 
LVL 24

Expert Comment

by:slyong
ID: 33623037
Does this help?


$query_Recordset4 = "SELECT * FROM ScheduledClasses WHERE ClassTypeName='Gun Safety' ORDER BY str_to_date(ClassDate, "%m/%d/%Y") ASC";

Open in new window

0
 
LVL 10

Accepted Solution

by:
jfromanski earned 2000 total points
ID: 33623045
The only DATE format supported by MySQL is YYYY-MM-DD (YY-MM-DD if YY is in 1970-2069 range).  So you have to convert or enter 9/14/2010 in 2010-09-14 format.
0
 
LVL 10

Expert Comment

by:honestman31
ID: 33623063
slyong  used PHP function to get the the time Stamp , I like this answer .
I like to use time stamp when dealing with time/date in MYSQL/ PHP , it's good habit to store your date/time in Mysql in time stamp format
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question