MYSQL order by time am/pm

删除回忆录丶 提交于 2019-11-30 15:30:39

You can do this by using STR_TO_DATE function in MySQL:

SELECT STR_TO_DATE('10.00pm','%h.%i%p');

try this:

SELECT * 
FROM table_name 
ORDER BY STR_TO_DATE(timeField,'%h.%i%p');

Example: SQLFiddle

In order to order it you need to format the date field fist.

try this

SELECT COl1, COl2, DATE_FORMAT(yourdate, '%k:%i:%s') AS mydate
FROM your_table
ORDER BY mydate 

Enjoy

SELECT * FROM table ORDER BY Name

This put everything in order for me: Alphabetized, Dates and Time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!