PWD Posted March 8, 2006 Share Posted March 8, 2006 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 Link to comment https://forums.phpfreaks.com/topic/4401-order-by-problem-with-dates/ Share on other sites More sharing options...
greycap Posted March 8, 2006 Share Posted March 8, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/4401-order-by-problem-with-dates/#findComment-15273 Share on other sites More sharing options...
PWD Posted March 8, 2006 Author Share Posted March 8, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4401-order-by-problem-with-dates/#findComment-15275 Share on other sites More sharing options...
wickning1 Posted March 8, 2006 Share Posted March 8, 2006 What column type is date_date? Is it a string type or a date type? Quote Link to comment https://forums.phpfreaks.com/topic/4401-order-by-problem-with-dates/#findComment-15301 Share on other sites More sharing options...
PWD Posted March 8, 2006 Author Share Posted March 8, 2006 It is formatted as a DATE Quote Link to comment https://forums.phpfreaks.com/topic/4401-order-by-problem-with-dates/#findComment-15313 Share on other sites More sharing options...
kenrbnsn Posted March 8, 2006 Share Posted March 8, 2006 Can you post a sample of the current output and how you want it to be displayed?Ken Quote Link to comment https://forums.phpfreaks.com/topic/4401-order-by-problem-with-dates/#findComment-15403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.