I am writing a calendar-based web application and am working on some code that will loop X amount of times and figure out the start/end dates & times of the future events. Each event has a start date/time and an end date/time The loop runs perfectly fine up until the year 2037, at which point the loop stop function properly. The conversion never takes place and reverts my dates back to 1969. Please see the code and output below. Can someone tell me why this is happening?
Live Example of Problem Behavior: http://codepad.org/h5ET3h2O
$date1 = strtotime('August 17 2011 8:00 AM');
for ($x=1; $x<=$repeatTimes; $x++){
echo date('m/d/Y g:i A', $date1)."<br><br>".$date1 ." +". $repeatFreq." ".$repeatUnit. " = ";
$date1 = strtotime(date('m/d/Y g:i A', $date1) . " +".$repeatFreq." ".$repeatUnit );
echo $date1."<br /><br />";
}
Output
08/15/2011 8:00 AM
1313409600 +1 Year = 1345032000
08/15/2012 8:00 AM
1345032000 +1 Year = 1376568000
08/15/2013 8:00 AM
1376568000 +1 Year = 1408104000
//Some Left Out
08/15/2036 8:00 AM
2102414400 +1 Year = 2133950400
//Problem starts here
08/15/2037 8:00 AM
2133950400 +1 Year =
12/31/1969 7:00 PM
+1 Year = 31536000
12/31/1970 7:00 PM
31536000 +1 Year = 63072000
12/31/1971 7:00 PM
63072000 +1 Year = 94694400
12/31/1972 7:00 PM
94694400 +1 Year = 126230400
12/31/1973 7:00 PM
126230400 +1 Year = 157766400
12/31/1974 7:00 PM
157766400 +1 Year = 189302400
//Some Left Out
UPDATE
I was able to utilize the DateTime Class to get the date working properly.
for ($x=1; $x<=$repeatTimes; $x++){
$date1->modify(" +".$repeatFreq." ".$repeatUnit);
$sDates[]=$date1->format('m/d/Y g:i A');
}