erme Posted February 23, 2010 Share Posted February 23, 2010 Hi I am trying to order by date so that the results are ordered by what's closet. This is what I have but doesn't work: SELECT * FROM $Table ORDER BY cast(Expiry as DateTime) DESC 'Expiry' being a date format such as 10/02/2010 Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted February 23, 2010 Share Posted February 23, 2010 Can you not do ORDER BY Expiry? Why cast? Quote Link to comment Share on other sites More sharing options...
erme Posted February 23, 2010 Author Share Posted February 23, 2010 Doesn't seem to work as a date. Because the fields are in the format 12/12/02 they don't get orders correctly. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 24, 2010 Share Posted February 24, 2010 Then use STR_TO_DATE() to fix that up first. Quote Link to comment Share on other sites More sharing options...
erme Posted February 25, 2010 Author Share Posted February 25, 2010 How does STR_TO_DATE() work? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 25, 2010 Share Posted February 25, 2010 How does STR_TO_DATE() work? The refman is your friend! 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.