|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-11-29 15:39 UTC] sean dot thorne at gmail dot com
Description:
------------
When asking strtotime for the 3rd thursday in a month and the first day of that month is thursday, it ignores the first thursday. It then begins to count after that first Thursday and returns the fourth Thursday.
Reproduce code:
---------------
$day = strtotime("3 Thursday Nov 2007");
echo date("m-d-Y", $day);
Expected result:
----------------
11-15-2007
Actual result:
--------------
11-22-2007
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 03:00:01 2025 UTC |
I also confirmed this. This is pretty serious, too! There are an infinite number of examples in which you can reproduce it; here are a few: // expect 06-15-2008, get 06-22-2008 $date = strtotime('3 Sunday June 2008'); echo date('m-d-Y', $date); // expect 07-08-2008, get 07-15-2008 $date = strtotime('2 Tuesday July 2008'); echo date('m-d-Y', $date); // expect 08-22-2008, get 08-29-2008 $date = strtotime('4 Friday August 2008'); echo date('m-d-Y', $date); // expect 09-29-2008, get 10-06-2008 $date = strtotime('5 Monday September 2008'); echo date('m-d-Y', $date); // expect 10-01-2008, get 10-08-2008 $date = strtotime('1 Wednesday October 2008'); echo date('m-d-Y', $date); Developers please take note: THIS IS A SERIOUS BUG! (and it's been around for a long time)Sorry to re-open, I found the same bug on: PHP Version 5.2.6-pl6-gentoo Some code to reproduce: <?php echo date('Y-m-d', strtotime('first Monday', mktime(0, 0, 0, 12, 1, 2008))); ?> Shows 2008-12-08, while indeed the first Monday in December is 2008-12-01.I had second thoughts about the "timestamp" passed into strtotime(), so I tried to create the date in a slightly different way but it failed never the less. I can also confirm this on 5.2.6_2 on FreeBSD. Additional code: Works: <?php // 2008-12-02 echo date('Y-m-d', strtotime('first Tuesday December 2008')); ?> Does not: <?php // 2008-12-08 echo date('Y-m-d', strtotime('first Monday December 2008')); ?>I stumbled onto this while searching for an answer. I'm using PHP v7.2.33 and am seeing this error. echo date('Y-m-d', strtotime('first Thursday October 2020')); echo "<br>"; echo date('Y-m-d', strtotime('first Friday October 2020')); echo "<br>"; 2020-10-08 2020-10-02