1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Rep Power

    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???
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Rep Power
    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".

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo