Get previous month value in PHP

后端 未结 5 1775
一生所求
一生所求 2021-01-12 09:38

I have used the below PHP function to get the previous month,

$currmonth = date(\'m\', strtotime(\'-1 month\'));

It was working fine and I

5条回答
  •  自闭症患者
    2021-01-12 10:22

    If you just need to get the month number of previous month, the following should suffice.

    $m = idate("m") - 1;
    // wrap to previous year
    if ($m < 1) {
        $m = 12 - abs($m) % 12;
    }
    

    This works with arbitrary number of subtracted months.

提交回复
热议问题