Blog > detail

Just my tiny mind

Conversion from 12 Hour to 24 Hour

26-2-2012 Admin General 2 Comments

Conversion from 12 Hour to 24 Hour

Many people using either 12 hour time format or 24 hour time format. It also easy for us to convert it into time format that we familiar with. We also can use both. However, database time format can only accept 24 hour time format. Therefore Conversion from 12 Hour to 24 Hour is a must.


For people that does not familiar with Conversion from 12 Hour to 24 Hour, I'll give an example.

12 hour time format24 hour time format
00:00 am00:00
01:00 am01:00
11:00 am11:00
12:00 pm12:00
01:00 pm13:00
11:00 pm23:00
00:00 am00:00

The PHP code that will handle this Conversion from 12 Hour to 24 Hour is below.


$ampm = "" //fill it either with am or pm

$hour = "" //fill it with hour

$min = "" //fill it with minute


if($ampm == 'PM' && $hour != 12)

{$hour = $hour + 12;}

echo "$hour:$min";


Congratulation we just made a simple Conversion from 12 Hour to 24 Hour programs.


Good luck.


Conversion from 12 Hour to 24 Hour Conversion from 12 Hour to 24 Hour

word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word

Conversion from 12 Hour to 24 Hour

Conversion from 12 Hour to 24 Hour

Conversion from 12 Hour to 24 Hour