Comment is the output I’m seeing. Help!
echo date("Y-m-t", strtotime("2012-07-31 -1 month")); //2012-07-31
echo date("Y-m-t", strtotime("2012-07-31 -2 month")); //2012-05-31
July has 31 days, so it can’t be processing it as August 1, right? Even if it were, the second line should work. Right?!
Thanks!
What’s happening here is, “7-31” minus one month comes out as “6-31”, which translates to “7-1”, which – asking for the last day of the month – comes out as “7-31”.
When you want to do month math, it’s almost always, if not always, better to build the time using mktime.
Note that when doing month math in mktime, always give ‘1’ as the day. Or really anything as long as it’s 28 or lower.