I have two hours format value
1) [start_time] => 07:30
2) [end_time] => 13:50
I want difference in hours between this two time.
For this case 07:30 to 13:50 it's difference of 6.00 hours.
so i need ans 6.00
I have two hours format value
1) [start_time] => 07:30
2) [end_time] => 13:50
I want difference in hours between this two time.
For this case 07:30 to 13:50 it's difference of 6.00 hours.
so i need ans 6.00
You can use DateTime classes, and use the diff()
method. Create two DateTime objects with the different times, and apply diff()
on one of them, with the other as the argument. Then you just print the format()
which is applicable, which in your example is %H:%I
.
$first = new DateTime("7:30");
$second = new DateTime("13:30");
$diff = $second->diff($first);
echo $diff->format("%H:%I"); // 06:00