Im attempting to code a little script that will work out hours.
I would like a travel time, start time and a finish time. The problem I'm having is getting the total time.
$travel = $_POST['travel']; // -- 1.00 (1 hour)
$start = $_POST['start']; // -- 7.30
$finish = $_POST['finish']; // -- 16.00
so the total time would be ( 16.00 - 7.30 ) + 1.00 = 9.5 hours
But this doesn't work because 16.00 - 7.30 = 8.7, then plus the 1 = 9.7.
I understand why its wrong, but not how to fix it. I cant change the time values to .50 for the half hour because the value is coming from a jquery plugin. Any help would be much appreciated.
// update
$a = new DateTime($_POST['start']);
$b = new DateTime($_POST['finish']);
$interval = $a->diff($b);
echo $interval->format("%H");
This works great, the only thing is how do I display hours and minutes e.g '9.00'