I'm trying to following code to get the difference in hours between 2 date/time values. The difference should be 47.82, but the result is 48.82. I can't figure out why.
$time1 = '11/03/2013 15:28:00';
$time2 = '11/01/2013 15:39:00';
$hourdiff = round((strtotime($time1) - strtotime($time2))/3600,2);
echo $hourdiff;
Any help is greatly appreciated.
The difference is likely due to daylight saving time.
You could set the dates to UTC which removes this issue.
$time1 = '11/03/2013 15:28:00 UTC';
$time2 = '11/01/2013 15:39:00 UTC';
$hourdiff = round( ( strtotime( $time1 ) - strtotime( $time2 ) ) / 3600, 2 );
Must be related to daylight saving. I see according to Google daylight saving in the US ends on 2 Nov which could be why. Try this and see if you get the correct result:
$time1 = '11/05/2013 15:28:00 <br/>';
$time2 = '11/03/2013 15:39:00';
Try this...
$diffHours = round(((strtotime($time1) - strtotime($time2)) / 3600),2);
In your equation you are not rounding on total result
Thanks