|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-11 19:21 UTC] re dot lewis at comcast dot net
Description:
------------
On Sept 11, 2009 I was calculating the date for each successive sunday and used the code below, but after Nov 1, 2009, the day changes to Saturday. Is this a bug? It appears to be related to daylight savings time.
Reproduce code:
---------------
<?php
for ($w= 5; $w < 15; $w++) {
echo date('Y-m-d, D, z', (strtotime('sunday') + $w*7*24*60*60)) . "<br>";
}
?>
Expected result:
----------------
Return the date of each sunday starting 5 weeks from this coming sunday.
Actual result:
--------------
2009-10-18, Sun, 290
2009-10-25, Sun, 297
2009-11-01, Sun, 304
2009-11-07, Sat, 310
2009-11-14, Sat, 317
2009-11-21, Sat, 324
2009-11-28, Sat, 331
2009-12-05, Sat, 338
2009-12-12, Sat, 345
2009-12-19, Sat, 352
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Jun 07 10:00:01 2026 UTC |
Which would be why it isn't a bug. Start with a timestamp around noon to avoid DST issues like this. You probably also want to use something like this instead: $db = new DateTime('2008-12-31'); $de = new DateTime('2009-12-31'); $di = DateInterval::createFromDateString('Sunday next week'); $dp = new DatePeriod($db, $di, $de, DatePeriod::EXCLUDE_START_DATE); foreach($dp as $dt) { echo $dt->format("F jS\n") . "<br>\n"; } This would give you the date of each Sunday in 2009, except the first one (because of the EXCLUDE_START_DATE) option.