kevin_newbie Posted July 5, 2009 Share Posted July 5, 2009 Hello, I was doing some research in the query string to order my list of month/years and it only does it alphabetically not by month/year how we view the calendar. For example if I have August 2006, September 2005, December 2006, March 2008, May 2010. The query says select DATE_FORMAT(dates,'%M %Y') as newDates creations where ORDER BY newDates. It orders it like this August 2006, December 2006, March 2008, May 2010, September 2005. I want it to order it like this though; May 2010, March 2008, December 2006, August 2006, September 2005. Is that possible Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2009 Share Posted July 5, 2009 ORDER BY dates DESC Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-869463 Share on other sites More sharing options...
corbin Posted July 5, 2009 Share Posted July 5, 2009 To elaborate a little, newDates is a string and is being ordered accordingly. Since it's a string, it's ordered alphabetically. Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-869465 Share on other sites More sharing options...
kevin_newbie Posted July 6, 2009 Author Share Posted July 6, 2009 It is ordering it alphabetically not by the months like January, February, March, April, May, June, July, August, September, October, November, December. Like with the query up above, it's putting May before March. It's suppose to be March before May. Now do you get what I mean? Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-869488 Share on other sites More sharing options...
PFMaBiSmAd Posted July 6, 2009 Share Posted July 6, 2009 ORDER BY dates DESC Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-869490 Share on other sites More sharing options...
ldougherty Posted July 6, 2009 Share Posted July 6, 2009 Since the field is a string there is no way to sort it as if it were a date because mySQL has no idea it's a date. Why not just make the field type date then you can sort by date as suggested. Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-869492 Share on other sites More sharing options...
kevin_newbie Posted July 6, 2009 Author Share Posted July 6, 2009 ORDER BY dates DESC PFMABiSmAD - I already did that and like I said in the previous post. It is ordering it alphabetically not by the months like January, February, March, April, May, June, July, August, September, October, November, December. Like with the query up above, it's putting May before March. It's suppose to be March before May. Now do you get what I mean? Idougherty - I did make the date column in mysql a datetime field. Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-869504 Share on other sites More sharing options...
fenway Posted July 7, 2009 Share Posted July 7, 2009 And it's still not working? Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-870565 Share on other sites More sharing options...
kevin_newbie Posted July 8, 2009 Author Share Posted July 8, 2009 Yeah its doing it alphabetically I don't want that. I want it in the months' order. Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-870723 Share on other sites More sharing options...
PFMaBiSmAd Posted July 8, 2009 Share Posted July 8, 2009 If you did an ORDER BY the_name_of_your_date_column it will work. Which is what I posted above. Your original query is trying to order by the result of the DATE_FORMAT() Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-870728 Share on other sites More sharing options...
kevin_newbie Posted July 8, 2009 Author Share Posted July 8, 2009 Thanks my fault. I tried it the first time it was mentioned then it sent out an error and it was my query that was screwed up since I added more things to it. Then the second time i tried it, it worked. thanks once again Quote Link to comment https://forums.phpfreaks.com/topic/164878-solved-order-by-monthyear-not-alphabetically/#findComment-870854 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.