Darkness Soul Posted December 20, 2006 Share Posted December 20, 2006 Yo, :)I need a logic help.. I have a varchar(*) field with date like JAN/2007, and I need to order this by the month (jan, feb, ...)I try to use if, unhappy..How I do it?Thank you..D.Soul Quote Link to comment https://forums.phpfreaks.com/topic/31354-solved-order-by-substring/ Share on other sites More sharing options...
artacus Posted December 20, 2006 Share Posted December 20, 2006 //begin lamentWhy oh why does everyone like to store dates as varchar?//end lamentThe "right" answer is store your dates as dates!The answer you are looking for is:[code]ORDER BY FIELD(MID(myDateField,1,3),'JAN','FEB','MAR',...)//where myDateField is well your date field in question.[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31354-solved-order-by-substring/#findComment-145265 Share on other sites More sharing options...
fenway Posted December 20, 2006 Share Posted December 20, 2006 If you wanted to be really fancy, you could STR_TO_DATE() it first... ;-) Quote Link to comment https://forums.phpfreaks.com/topic/31354-solved-order-by-substring/#findComment-145317 Share on other sites More sharing options...
Darkness Soul Posted December 20, 2006 Author Share Posted December 20, 2006 str_to_date may help a lot, order by field too, but that database isn't mine, and the data storage there is a mess.. i found dates like jan/2005, fev/02, agos/2002, 05/2001.. it have no standard.. =Sthankx for the help Quote Link to comment https://forums.phpfreaks.com/topic/31354-solved-order-by-substring/#findComment-145340 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.