How to find out what the date was 5 days ago?

后端 未结 10 1697
一整个雨季
一整个雨季 2020-12-24 04:46

Well, the following returns what date was 5 days ago:

$days_ago = date(\'Y-m-d\', mktime(0, 0, 0, date(\"m\") , date(\"d\") - 5, date(\"Y\")));
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 05:20

    Use the built in date_sub and date_add functions to math with dates. (See http://php.net/manual/en/datetime.sub.php)

    Similar to Sazzad's answer, but in procedural style PHP,

    $date = date_create('2008-12-02');
    date_sub($date, date_interval_create_from_date_string('5 days'));
    echo date_format($date, 'Y-m-d'); //outputs 2008-11-27
    

提交回复
热议问题