stevenh Posted December 29, 2011 Share Posted December 29, 2011 I have a varchar field called date that looks like this "2/06/2011 TUE" or like this "10/05/2011 WED". When I do an Order BY date Desc in php it does Not sort properly. Thanks for your assistance Steve Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 29, 2011 Share Posted December 29, 2011 Why would you ever want to store dates in this fashion? Either use unix timestamps or MySQL's DATE/TIME/DATETIME. And to answer your question, sorting varchars that contain numbers doesn't yield good results. Quote Link to comment Share on other sites More sharing options...
stevenh Posted December 29, 2011 Author Share Posted December 29, 2011 I did Not create the code, I inherited it. How can I sort it in PHP? Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 29, 2011 Share Posted December 29, 2011 What kind of sorting to do you want to do? You could use strtotime to make it a unix timestamp and then sort it that way. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 29, 2011 Share Posted December 29, 2011 Use MySQL's STR_TO_DATE() function, and order by it. Quote Link to comment 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.