how do I subtract 24 hour from date time object in PHP

后端 未结 10 1402
我寻月下人不归
我寻月下人不归 2020-12-17 07:57

I have the following code:

  $now = date(\"Y-m-d H:m:s\");
  $date = date(\"Y-m-d H:m:s\", strtotime(\'-24 hours\', $now));

However, now it

10条回答
  •  眼角桃花
    2020-12-17 08:09

    $now = date("Y-m-d H:i:s");
    $date = date("Y-m-d H:i:s", strtotime('-24 hours', strtotime($now)));
    

    Add "strtotime" before $now, and Y-m-d H:m:s replace with Y-m-d H:i:s

提交回复
热议问题