Solved

How to properly order dates in a record set

Posted on 2010-09-07
3
268 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 500 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 …

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now