Jump to content

Archived

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

PWD

ORDER BY problem with dates

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...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
date_date is the literal name of the column. I did try your suggestion to no avail. I also tried to completely remove the alias (AS date_date...) to no avail...

Still searching

Share this post


Link to post
Share on other sites
Can you post a sample of the current output and how you want it to be displayed?

Ken

Share this post


Link to post
Share on other sites

×

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.