I have this code that I'm trying to modify. When I enter a start time for 21:00 and an end time for 07:00
The existing code returns a negative number.
I would like the function to assume that midnight passes if the original code returns a negative number and calculate duration. I need it to return the duration in the same format.
Thank in advance for any help.
protected function getDuration($fromTime, $toTime) {
list($startHour, $startMin) = explode(':', $fromTime);
list($endHour, $endMin) = explode(':', $toTime);
$durationMinutes = (intVal($endHour) - intVal($startHour)) * 60 + (intVal($endMin) - intVal($startMin));
$hours = $durationMinutes / 60;
return number_format($hours, 2);
}