PHP date comparison

后端 未结 9 525
长情又很酷
长情又很酷 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:41

    Just adding another answer, using strtotime's relative dates:

    $date = '2008-02-16 12:59:57';
    if (strtotime("$date +1 day") <= time()) {
        // Do something
    }
    

    I think this makes the code much more readable.

    0 讨论(0)
  • 2021-02-02 16:41

    You can use Simple PHP to do this:

    $date = new simpleDate();
    echo $date->now()->subtractHour(24)->compare('2008-02-16 12:59:57')->isBefore();
    
    0 讨论(0)
  • 2021-02-02 16:43
    if (strtotime("2008-02-16 12:59:57") >= time() - 24 * 60 * 60)
    { /*LESS*/ }
    
    0 讨论(0)
提交回复
热议问题