Given a time, how can I find the time one month ago

后端 未结 7 1545
梦如初夏
梦如初夏 2021-01-13 08:16

Given a time, how can I find the time one month ago.

7条回答
  •  孤独总比滥情好
    2021-01-13 08:41

    PHP 5.2=<

    $date = new DateTime(); // Return Datetime object for current time
    $date->modify('-1 month'); // Modify to deduct a month (Also can use '+1 day', '-2 day', ..etc)
    echo $date->format('Y-m-d'); // To set the format 
    

    Ref: http://php.net/manual/en/datetime.modify.php

提交回复
热议问题