|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-02 23:15 UTC] matt at iws dot co dot nz
Description:
------------
Asking strtotime() for the date of the first occurrence of a particular day of the week, when that day of the week is also the first day of the month, returns the incorrect day. See examples below.
Reproduce code:
---------------
echo date('Y-m-d', strtotime('first monday jan 2007'));
echo date('Y-m-d', strtotime('first monday feb 2007'));
echo date('Y-m-d', strtotime('first thursday feb 2007'));
echo date('Y-m-d', strtotime('first thursday jan 2007'));
Expected result:
----------------
// First Monday Jan 2007
2007-01-01
// First Monday Feb 2007
2007-02-05
// First Thursday Feb 2007
2007-02-01
// First Thursday Jan 2007
2007-01-04
Actual result:
--------------
// First Monday Jan 2007 - incorrect
2007-01-08
// First Monday Feb 2007 - correct
2007-02-05
// First Thursday Feb 2007 - incorrect
2007-02-08
// First Thursday Jan 2007 - correct
2007-01-04
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 07:00:01 2025 UTC |
Shouldn't "Second Monday Jan 2007" and "Second Tuesday Jan 2007" return days consecutive days in Jan 2007, instead of dates one week apart? "Second Monday Feb 2007" and "Second Tuesday Feb 2007" return the correct results. As far as I can tell the results are always inconsistent for the weekday that is the first day of the month. Example Code: ------------- echo date('Y-m-d', strtotime('second monday jan 2007')); // returns 2007-01-15 echo date('Y-m-d', strtotime('second tuesday jan 2007')); // returns 2007-01-09