开发者

Can MySQL properly sort DATETIME columns when the values have been formatted with DATE_FORMAT?

开发者 https://www.devze.com 2023-03-12 09:10 出处:网络
Pretty much self-explanatory. Can MySQL sort dates (i.e. not alphabetically but like a date) when the dates have been formatted with DATE_FORMAT?

Pretty much self-explanatory. Can MySQL sort dates (i.e. not alphabetically but like a date) when the dates have been formatted with DATE_FORMAT?

Specifically, in my case, only the DATE part has been extracted from the DAT开发者_JAVA百科ETIME values.


Yes.

ORDER BY DATE(`date_time`) DESC

If you have already calculated this when selecting columns, just use its alias.

SELECT DATE(`date_time`) AS `date`
    FROM `table`
ORDER BY `date` DESC
0

精彩评论

暂无评论...
验证码 换一张
取 消