MYSQL time order am / pm

I have a row in a table that contains the time of day in am / pm format, for example.

timeField --------- 9.00am 10.00pm 7.00am etc... 

Is there a way in mysql to arrange these values?

+4
source share
3 answers

You can do this using STR_TO_DATE in MySQL:

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

try the following:

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

Example: SQLFiddle

+13
source

To order it, you need to format a piece of date.

try it

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

Enjoy

+1
source
 SELECT * FROM table ORDER BY Name 

This is all for me: Alphabet, Dates and Time

0
source

Source: https://habr.com/ru/post/1440506/


All Articles