PHP Strtotime -1month -2month

前端 未结 6 570
感情败类
感情败类 2020-12-06 06:00

This was working fine yesterday with no changes to the code.

echo date(\"M\", strtotime(\"-3 month\", time()) );
echo date(\"M\", strtotime(\"-2 month\", tim         


        
6条回答
  •  -上瘾入骨i
    2020-12-06 06:31

    From PHP 5.3 (Ref: https://bugs.php.net/bug.php?id=44073) and higher you can do:

    "first day of +1 month" or "first day of next month" or even "last day of next month"

    Example:

    $date = '2015-12-31';
    
    echo date("Y-m-d", strtotime($date ."first day of previous month"));
    

    Will produce: 2015-11-01 This does not calculate days on +30 days time basis.

提交回复
热议问题