简体   繁体   中英

change time format in mysql query ORDER BY

i am working on project where user have database with date stored in normal format 8 March 2013 and i want to sort the output with date .. but not getting right output bcos time stamp not used .... so is there way i can use or convert that date field to time stamp inside mysql query

SELECT * FROM imdb WHERE year ='2012' ORDER BY `date` DESC LIMIT 20

i want some thing like this

SELECT * FROM imdb WHERE year ='2012' ORDER BY strtotime(`date`) DESC LIMIT 20

but i know this wont work ... is there a way out

since it is not a date, use STR_TO_DATE to convert string to date

SELECT * 
FROM imdb 
WHERE year ='2012' 
ORDER BY STR_TO_DATE(`date`, '%e %M %Y') DESC 
LIMIT 20

尝试这个::

SELECT * FROM imdb WHERE year ='2012' ORDER BY DATE(`date`) DESC LIMIT 20

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM