Reputation:
This is my code:
SELECT id, title, date FROM table ORDER BY STR_TO_DATE(date,"%m/%d/%Y %h:%i:%s")
The date output is:
2016-12-11 14:40:00
2016-11-15 08:50:09
2016-11-15 08:54:58
SELECT id, title, date FROM table ORDER BY STR_TO_DATE(date,"%m/%d/%Y %h:%i:%s") DESC
doesn't work for me for some reason.
How can I reach to ORDER BY this?
2016-11-15 08:54:58
2016-11-15 08:50:09
2016-12-11 14:40:00
Edit: date
is stored as timestamp
in my MySQL database!
Upvotes: 1
Views: 487
Reputation: 1242
Assume you want the data that order by date ascending and time descending.
You can try this:
SELECT id, title, date
FROM table
ORDER BY DATE(date) ASC , TIME(date) DESC
Upvotes: 2