|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-12-13 16:59 UTC] kugel at rci dot rutgers dot edu
Description: ------------ --- From manual page: http://www.php.net/function.strtotime#Changelog --- "5.2.7 In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month would incorrectly add one week to the returned timestamp. This has been corrected in 5.2.7 and later versions." Contrary to the above, this bug still exists in PHP 5.2.13, 5.2.14, and 5.3.3. Test script: --------------- <?php date_default_timezone_set("America/New_York"); echo date("D, M j Y", strtotime("first Saturday January 2011 8:00pm")) . "\n"; echo date("D, M j Y", strtotime("third Saturday January 2011 8:00pm")) . "\n"; ?> Expected result: ---------------- Sat, Jan 1 2011 Sat, Jan 15 2011 Actual result: -------------- Sat, Jan 8 2011 Sat, Jan 22 2011 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 20:00:01 2025 UTC |
This is not a *code* bug though. It works like follows: "January 2011 8:00pm" is an absolute date string, which processed first: $ php -r 'echo date("Y-m-d H:i:s", strtotime("January 2011 8:00pm"));' 2011-01-01 20:00:00 $ php -r 'echo strtotime("January 2011 8:00pm");' 1293912000 "first Saturday" is a string relative to the absolute date string, which is processed next: $ php -r 'echo date("Y-m-d H:i:s", strtotime("first Saturday", 1293912000));' 2011-01-08 00:00:00 You are missing the "of" keyword, which links the two together: $ php -r 'echo date("Y-m-d H:i:s", strtotime("first Saturday of January 2011 8:00pm")), "\n";' 2011-01-01 20:00:00 $ php -r 'echo date("Y-m-d H:i:s", strtotime("third Saturday of January 2011 8:00pm")), "\n";' 2011-01-15 20:00:00