I have a time as a string, for example:
$time = '5:36 pm';
I require this to be in 24 hour format (i.e. 17:36
), however I don't know which functions I need to use to convert it. Please help.
Converting time from a 12-hour clock to a 24-hour clock To work out the 24-hour reading of an afternoon time (PM), you must add 12 to the hour shown on a 12-hour clock. For example, 1:00 PM (12-hour) would become 13:00 (24-hour).
$time = '23:45'; echo date('g:i a', strtotime($time));
In SQL Server 2012, we can use Format function to have suitable date time format. Use capital letter 'HH:mm:ss' for 24 hour date time format.
// 24-hour time to 12-hour time
$time_in_12_hour_format = date("g:i a", strtotime("13:30"));
// 12-hour time to 24-hour time
$time_in_24_hour_format = date("H:i", strtotime("1:30 PM"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With