Click Upvote Click Upvote - 1 year ago 142
MySQL Question

Converting an AM/PM time to 24 hours format using PHP or MySQL?

I have a string of time such as: 6:00 AM, 7:30 PM, etc. It can easily be changed to 6:00:00 AM, 7:30:00 PM, etc as well.

I'm looking for a way to quickly convert this time into a 24 hour format, e.g 7:30 PM = 19:30:00.

Is there any PHP or MySQL function which has this capability, or do I have to devise my own?

Answer Source
STR_TO_DATE( `column_here`, '%l:%i %p' )

Read more here.


Edited '%l:%M %p' to '%l:%i %p'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download