Solved

How to properly order dates in a record set

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

19 Experts available now in Live!

Get 1:1 Help Now