Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to properly order dates in a record set

Posted on 2010-09-07
3
Medium Priority
?
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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