0

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.

hatched
  • 795
  • 2
  • 9
  • 34
  • 1
    Maybe [this post](https://stackoverflow.com/questions/5489502/how-to-get-previous-month-and-year-relative-to-today-using-strtotime-and-date) is relevant here. – Anderson Green Oct 31 '18 at 08:34

2 Answers2

0

Try this:

$currmonth = date('F', mktime(0, 0, 0, date('m') - 1, 1, date('Y')));

Output :

September
TrickStar
  • 229
  • 4
  • 19
0
$dt = new DateTime('first day of last month');
echo $dt->format('m');
// 09
hausl
  • 160
  • 16