Reputation: 2418
echo date('Y-m-d', strtotime('First Monday '.date('F o', strtotime("-4 months")));
The above code returns 2012-10-08, which is incorrect - the first monday of october 2012 should return 2012-10-01.
The changelog from the manual (http://php.net/manual/en/function.strtotime.php) specifies the following:
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.
It seems to be clear that this is what's causing the wrong return date, however I'm using PHP version 5.4.7 (running xamp on localhost)!
Any ideas?
Upvotes: 2
Views: 3997
Reputation: 25552
You are missing the keyword of
when trying to retrieve the first day of the month
echo date('Y-m-d', strtotime('First Monday of '.date('F o', strtotime("-4 months")));
I found the info on this bug report
My current version is PHP 5.4.4 in case it still does not work for you
Upvotes: 7