|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-11-03 03:19 UTC] herrnoel at gmail dot com
Description:
------------
Actual php version is latest from debian stable: PHP 5.2.6-1+lenny3
When using strtotime() for some really handy english parsing, it works great EXCEPT for the first day of the month.
The format is as follows:
[1-4] [day of week] [month] [year]
If the day of the week is the first day of the month, this will return the date starting one week ahead of the first day of the month. Otherwise, the behavior is as expected.
This is repeatable for all months. If you leave out the initial digit, the broken first day of the month works, but then you must use 1 to indicate the 2nd instance of that day and so on.
Reproduce code:
---------------
echo date('Y-m-d', strtotime('1 thu oct 2009')); # first day of month
echo date('Y-m-d', strtotime('1 fri oct 2009')); # second day of month
echo date('Y-m-d', strtotime('1 sun nov 2009')); # first day of month
echo date('Y-m-d', strtotime('2 sun nov 2009')); # second sunday of month (sunday is the first day of month)
Expected result:
----------------
2009-10-01
2009-10-02
2009-11-01
2009-11-08
Actual result:
--------------
2009-10-08
2009-10-02
2009-11-08
2009-11-15
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 12:00:01 2025 UTC |
OK thanks for the clarification. Yes the docs could be improved for this particular function on php.net. Interestingly enough, I found a syntax that seems to work: strtotime('+0 week sun nov 2009'); strtotime('+1 week sun nov 2009'); strtotime('-1 week sun nov 2009'); etc. This seems to yield valid timestamps and gives me an easy integer based interval incrementer. I'm parsing ical RRULE sets. Believe me I'm grateful for this function's existence.