Reputation: 335
This is strange.I need a list of dates to be ordered with the most recent date at top.Data Type for date is varchar. Using order by DESC doesn't seem to be working the way I want it to.
Select * from invoice
ORDER BY date DESC
It gives me the date ordered by day like
30/11/2017
23/11/2017
21/06/2017
02/12/2017
01/12/2017
Needs to be like:
02/12/2017
01/12/2017
30/11/2017
23/11/2017
21/06/2017
Upvotes: 1
Views: 518
Reputation: 521419
Use STR_TO_DATE
:
SELECT *
FROM invoice
ORDER BY STR_TO_DATE(date, '%d/%m/%Y') DESC;
Note that it is generally undesirable to store your dates as text, for the very reason you have already seen. It makes it much more difficult to work with your date information.
Upvotes: 2