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;
daylight savings time messing up date calculation
Moderator: General Moderators
-
maneetpuri
- Forum Commoner
- Posts: 60
- Joined: Tue Oct 07, 2008 6:32 am
Re: daylight savings time messing up date calculation
Hi,
Try using functions round() and ceil(), this should solve the problem.
Cheers,
Try using functions round() and ceil(), this should solve the problem.
Cheers,
Re: daylight savings time messing up date calculation
Beautiful. Thank you. Thanks for mentioning ceil() as well as round().