开发者

mysql sort string as date not as string

开发者 https://www.devze.com 2023-02-02 21:46 出处:网络
The DB I inherited stored there dates like:yyy-mm-dd hh:mm:ss I was hoping to sort by date in my mysql query but it is treating them like a string and sorting accordingly.

The DB I inherited stored there dates like: yyy-mm-dd hh:mm:ss

I was hoping to sort by date in my mysql query but it is treating them like a string and sorting accordingly.

Any one know of a way to sort them as a date and not a string in the query itself?

Thanks, Rob开发者_开发百科ert


You can try casting the value to a date and sorting by that:

ORDER BY CAST(SDate As DATETIME);
0

精彩评论

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