How to get previous year using PHP

前端 未结 9 752
生来不讨喜
生来不讨喜 2021-02-01 01:30

How am I able to get the value of the previous year using PHP. Are there any predefined functions for it?

9条回答
  •  一生所求
    2021-02-01 01:36

    This thread needs an update.

    Nowadays you would use the PHP date-time object and do something like this:

    $lastYear = new DateTime();
    $lastYear->sub(new DateInterval('P1Y'));
    echo $lastYear->format('Y');
    

提交回复
热议问题