|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-12-01 17:07 UTC] phil at goli dot at
Description:
------------
the problem described occurs only in the version 4.4.7
the script below produces the following output when run as a web-script:
$myFirstAdvent: 12-02
$mySecondAdvent: 12-09
$myThirdAdvent: 12-16
$myFourthAdvent: 12-23
the script below produces the following output when run via command line:
$myFirstAdvent: 12-02
$mySecondAdvent: 12-02
$myThirdAdvent: 12-02
$myFourthAdvent: 12-02
Reproduce code:
---------------
<?php
$myTmp = strtotime("first Sunday", mktime(0, 0, 0, 11, 27, 2007) ); // date("Y", myDST())
$myFirstAdvent = date("m-d", $myTmp);
$myTmp = strtotime("next Sunday", $myTmp);
$mySecondAdvent = date("m-d", $myTmp);
$myTmp = strtotime("next Sunday", $myTmp);
$myThirdAdvent = date("m-d", $myTmp);
$myTmp = strtotime("next Sunday", $myTmp);
$myFourthAdvent = date("m-d", $myTmp);
echo '$myFirstAdvent: ' . $myFirstAdvent . "\n";
echo '$mySecondAdvent: ' . $mySecondAdvent . "\n";
echo '$myThirdAdvent: ' . $myThirdAdvent . "\n";
echo '$myFourthAdvent: ' . $myFourthAdvent . "\n";
?>
Expected result:
----------------
if run in the command line it should also the correct dates:
$myFirstAdvent: 12-02
$mySecondAdvent: 12-09
$myThirdAdvent: 12-16
$myFourthAdvent: 12-23
Actual result:
--------------
if run in the command line it displays these dates:
$myFirstAdvent: 12-02
$mySecondAdvent: 12-02
$myThirdAdvent: 12-02
$myFourthAdvent: 12-02
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 15:00:01 2025 UTC |
For clarification, strtotime will not advance to "Next Sunday" if it is given a date that lands on a Sunday. Here is a workaround if you are writing something that needs to advance to the next Sunday, but you may not be giving it a date that starts with a sunday every time (in my case something that splits up weeks of a month): $i was a result of a for loop, in my case. if(date('D',$your_date) == 'Sun'){ $sunday_offset = 1; } else { $sunday_offset = 0; } $next_sunday = strtotime("next Sunday +" . ($i+$sunday_offset) . "week", $your_date);