Strtotime giving wrong date


I am using strtotime to work out the date of the second monday of a particular month.

So I am trying to find out the second Monday of November which should be 8th but its bringing back the 15th, which is actually the 3rd week

Can someone please explain why this is doing this?

function secondMonday($date) {
	$nextmonth = strtotime(date('Y-m-01', strtotime("$date +1 month")));
	$secondMonday = gmdate('Y-m-d', strtotime('second Monday', $nextmonth));
	return $secondMonday;

echo secondMonday('2010-10-11 00:01:00');


I am afraid not that is displaying “11-08-2010” and not “12-08-2010”

Which PHP version are you using? Life will be easy with 5.3.x (as Anthony demonstrated) and slightly less so with 5.2.x.

check it once again…

it’s working…

echo date('r', strtotime('second monday of october')); #Mon, 11 Oct 2010 00:00:00 +0100

I have version 5.2 :frowning:

The changing of 01 to 00 works for second monday in November but it doesn’t work for second Thursday in August.

It should give me 12th but it gives me the 11th

function secondMonday($date) {
	$nextmonth = strtotime(date('Y-m-00', strtotime("$date +1 month")));
	$secondMonday = gmdate('d-m-Y', strtotime('second Thursday', $nextmonth));
	return $secondMonday;

echo secondMonday('2010-07-01');

use this $nextmonth = strtotime(date(‘Y-m-00’, strtotime(“$date +1 month”)));

instead of $nextmonth = strtotime(date(‘Y-m-01’, strtotime(“$date +1 month”)));