I’m trying to get every X days from a given date for a calendar. I think I have the logic down to an extent, but for a small window of dates I am getting unexpected results.
My code below taken from my project:
$start_time = 1345935600; //Sept 25th 2011;
$end_time = 1355011200; //Dec 9th 2011;
$sStartDate = date("Y-m-d", $start_time) . " " . date("H:i:s", strtotime("00:00:00"));
$sEndDate = date("Y-m-d", $end_time) . " " . date("H:i:s", strtotime("00:00:00"));
$sCurrentDate = $sStartDate;
while($sCurrentDate < $sEndDate)
{
$t_date = strtotime($sCurrentDate);
$s_date = strtotime(date("Y-m-d", strtotime("08/30/2011")));
$recurs_every = 60 * 60 * 24 * 2; //occurs every 2 days
echo date("Y-m-d H:i:s", $t_date) . " " . date("Y-m-d H:i:s", $s_date) . " " . (($t_date - $s_date) % $recurs_every) . " " . $recurs_every . "<BR>" ;
$sCurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));
}
Outputs (current date – start date – modular) :
2011-09-25 00:00:00 2011-08-30 00:00:00 0
2011-09-26 00:00:00 2011-08-30 00:00:00 86400
....
2012-10-27 00:00:00 2011-08-30 00:00:00 0
2012-10-28 00:00:00 2011-08-30 00:00:00 86400
2012-10-29 00:00:00 2011-08-30 00:00:00 3600
2012-10-30 00:00:00 2011-08-30 00:00:00 90000
2012-10-31 00:00:00 2011-08-30 00:00:00 3600
2012-11-01 00:00:00 2011-08-30 00:00:00 90000
2012-11-02 00:00:00 2011-08-30 00:00:00 3600
2012-11-03 00:00:00 2011-08-30 00:00:00 90000
2012-11-04 00:00:00 2011-08-30 00:00:00 3600
2012-11-05 00:00:00 2011-08-30 00:00:00 90000
The last few lines are the issue for me.
3600 is one hour and I don’t know where this is coming from. Strange thing is, fast forward to march 26 2012 and it starts to work again but same error occurs at Oct 29 2012…
I’ve been at this for a few hours and can’t figure this out. Any help really appreciated!
Thanks
In some contries there is a summer & winter time where the clock is converted one hour (@ 27 march & 30 oct). Therefore there is a one hour difference.
-> http://en.wikipedia.org/wiki/Daylight_saving_time
Example: