February 24th, 2013, 12:23 AM
Convert standard time to military time
Hello! I have this column in my database with a datatype of TIME.
I want to convert them into military time. I can convert military to standard but can't if vice versa. How can I convert standard to military.
[MYSQL]SELECT TIME_FORMAT('22:00', '%h:%i %p')[/MYSQL] ---> 10:00 PM
[MYSQL]SELECT TIME_FORMAT('10:00 PM', '%H:%i')
SELECT TIME_FORMAT('10:00 PM', '%T')[/MYSQL] --> 10:00, 10:00:00 respectively.
Any help guys???
February 24th, 2013, 01:17 AM
You will need to use STR_TO_DATE and pass it the appropriate format codes in order to convert a 12-hour time to a 24-hour time. When TIME_FORMAT parses its first argument, it only accepts 24-hour time; therefore, "10:00 PM" evaluates to "10:00 AM".