PHP date() and strtotime() return wrong months on 31st

As mentioned within the documentation, you should pass the date for the first day of the current month as the second parameter to the strtotime() function:

$base = strtotime(date('Y-m',time()) . '-01 00:00:01');
echo date('m/Y',strtotime('+0 month', $base));
echo date('m/Y',strtotime('+1 month', $base));
echo date('m/Y',strtotime('+2 month', $base));

See that it works: http://ideone.com/eXis9

01/2012

02/2012

03/2012

Leave a Comment