Jump to content

ORDER BY problem with dates


PWD

Recommended Posts

What is the best way to format my MySQL query if I want to display my [b]dates[/b] in ascending order?
Currently, as written, my query sorts my dates [b]alphabetically[/b], and I want it sorted numerically:

[code]$query = "SELECT DATE_FORMAT(date_date,'%M %D %Y') AS date_date,date_info from imp_dates ORDER BY date_date ASC";[/code]

My search of the MySQL website must not be correct as I'm not producing any results about this.

My gratitude ahead of time for your help...

Link to comment
https://forums.phpfreaks.com/topic/4401-order-by-problem-with-dates/
Share on other sites

[!--quoteo(post=352727:date=Mar 7 2006, 09:31 PM:name=PWD)--][div class=\'quotetop\']QUOTE(PWD @ Mar 7 2006, 09:31 PM) [snapback]352727[/snapback][/div][div class=\'quotemain\'][!--quotec--]
What is the best way to format my MySQL query if I want to display my [b]dates[/b] in ascending order?
Currently, as written, my query sorts my dates [b]alphabetically[/b], and I want it sorted numerically:

[code]$query = "SELECT DATE_FORMAT(date_date,'%M %D %Y') AS date_date,date_info from imp_dates ORDER BY date_date ASC";[/code]

My search of the MySQL website must not be correct as I'm not producing any results about this.

My gratitude ahead of time for your help...
[/quote]

It may be that you are hiding the column name with your alias. Your orderby is probably looking at the alias and not the original column.

Try this:

SELECT DATE_FORMAT(date_date,'%M %D %Y') AS date_string,date_info from imp_dates ORDER BY date_date ASC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.