Bizzare PHP behaviour calculating time differences, only on 6th and 7th September, 2013 -
i'm trying calculate difference in days between 2 dates. i'm getting bizzare behaviour - i've narrowed down 6th , 7th october, 2013, can see below. whenever date range spans dates, calculation day out.
// wrong! current year - 2013 $datediff = strtotime('2013-10-07') - strtotime('2013-10-06'); $starttoenddays = floor($datediff/(60*60*24)); print_r($starttoenddays); // outputs 0 - should output 1 // right! next year - 2014 $datediff = strtotime('2014-10-07') - strtotime('2014-10-06'); $starttoenddays = floor($datediff/(60*60*24)); print_r($starttoenddays); // outputs 1 - correct
any idea issue here?
haha ok, turns out 6th/7th october 2013 when daylight savings starts in sydney, australia. so, number of hours between dates calculated (correctly) 23. but, 23 hrs not quite day.
if you're using php 5.3+, how should calculate difference between dates in days, save daylight savings headaches:
$startdate = new datetime('2013-10-07'); $enddate = new datetime('2013-10-06'); $interval = $startdate->diff($enddate); $days = $interval->days;
Comments
Post a Comment