|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-11-27 17:21 UTC] venaas@php.net
[2001-11-27 17:38 UTC] derick@php.net
[2001-11-27 17:42 UTC] james at composite dot co dot nz
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 22:00:01 2025 UTC |
While trying to get a list of dates between any two given dates by adding 86400 (secs per day) to each consecutive datetime, I discovered that adding 86400 (secs per day) to the 3rd Sunday of March (in any year) results in a datetime which is interpreted by the date() function as 23:00 hrs on the same Sunday - rather then 00:00 hr on the following day, as it should be. There also seems to be a similar effect in reverse some time in October. Have a look at the result of the following script, using any range of dates in $datetime_temp and $datetime_end. <?php $datetime_temp = strtotime("2002-1-1"); $datetime_end = strtotime("2002-12-31"); echo "start: ".date("Y-n-j H:i:s", $datetime_temp); echo " end: ".date("Y-n-j H:i:s", $datetime_end)."<br/>\n"; $datetimes = array(); while($datetime_temp <= $datetime_end) { $datetimes[] = $datetime_temp; echo date("Y-n-j H:i:s", $datetime_temp)."<br/>\n"; $datetime_temp += 86400; } ?> Partial output: ... 2002-3-15 00:00:00 2002-3-16 00:00:00 2002-3-17 00:00:00 2002-3-17 23:00:00 2002-3-18 23:00:00 2002-3-19 23:00:00 ... 2002-10-3 23:00:00 2002-10-4 23:00:00 2002-10-5 23:00:00 2002-10-7 00:00:00 2002-10-8 00:00:00 2002-10-9 00:00:00 ... What's happening? Is there another/better way for me to get my list of dates?