Jump to content

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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