Page 1 of 1

daylight savings time messing up date calculation

Posted: Mon Feb 23, 2009 6:30 pm
by rhecker
I need to calculate the number of days between two dates as an integer. Daylight savings time screws up the number of days. My code is as follows:

$firstdate = strtotime($courseset["startdate"]);
$seconddate = strtotime($courseset["enddate"]);
$days = ($seconddate - $firstdate) / (60 * 60 * 24);

If I add the following to force $days to be an integer, it doesn't round correctly:

$days = (int) $days;

Re: daylight savings time messing up date calculation

Posted: Tue Feb 24, 2009 1:24 am
by maneetpuri
Hi,

Try using functions round() and ceil(), this should solve the problem.

Cheers,

Re: daylight savings time messing up date calculation

Posted: Tue Feb 24, 2009 11:08 am
by rhecker
Beautiful. Thank you. Thanks for mentioning ceil() as well as round().