PHP date comparison

后端 未结 9 545
长情又很酷
长情又很酷 2021-02-02 16:10

How would I check if a date in the format \"2008-02-16 12:59:57\" is less than 24 hours ago?

9条回答
  •  滥情空心
    2021-02-02 16:29

    Maybe it will be more easy to understand...

    $my_date        = '2008-02-16 12:59:57';
    $one_day_after  = date('Y-m-d H:i:s', strtotime('2008-02-16 12:59:57 +1 days'));
    
    if($my_date < $one_day_after) {
    echo $my_date . " is less than 24 hours ago!";
    } else {
    echo $my_date . " is more than 24 hours ago!";
    }
    

提交回复
热议问题