简体   繁体   English

在 mysql 查询 ORDER BY 中更改时间格式

[英]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我正在开发一个项目,其中用户的数据库的日期以正常格式存储在2013 年 3 月 8 日,我想用日期对输出进行排序.. 但没有得到正确的输出 bcos 时间戳未使用......所以有什么方法可以使用或将该日期字段转换为 mysql 查询中的时间戳

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由于它不是日期,请使用STR_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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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