strtotime()
uses 30 day months and there are only 28 in days in February (this year) so will not yield a valid date in February. You could use the current day d
or j
and subtract that which will always put you in the previous month (-29 days
):
$prevmonth = date('M', strtotime('-' . date('d') . ' days'));
This will get December
from January
as well.