0

I have a function which calculate the difference between two timestamps,

public static function getDuration($from, $to) {
    $duration = $to - $from; 
    return $duration;
}

but this is not working as required. example, if i pass,

$difference = getDuration(strtotime('19-07-2012 23:00:00'), strtotime('20-07-2012 4:45:00'));
echo $difference/3600;

it returns 5.75 instead of 5.45, when converted to hours.

Harish Kurup
  • 7,257
  • 19
  • 65
  • 94

1 Answers1

4

it returns ok - 5,75 is 5 3/4 hours = 5 hours 45 minutes

It returns in decimal - not hours/minutes

if you want hours/minutes you can use:

$hours=floor($difference/3600);
$minutes=$difference/60-$hours*60;
Jerzy Zawadzki
  • 1,975
  • 13
  • 15