This question already has an answer here:
I'm trying to get previous month of current month.
For example, current month is October , the value return should be September.
I've tried
$currmonth = date('m', strtotime('-1 month'));
But it return the same month - October. But when I replace to -2month
, it will return August which is correct.
</div>
Try this:
$currmonth = date('F', mktime(0, 0, 0, date('m') - 1, 1, date('Y')));
Output :
September
$dt = new DateTime('first day of last month');
echo $dt->format('m');
// 09