开发者

Can MySQL properly sort DATETIME columns when the values 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜