Solved

How to properly order dates in a record set

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…
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.

821 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