PHP date comparison

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

    e.g. via strtotime and time().
    The difference must be less then 86400 (seconds per day).

    prints

    now: 2009-12-03 18:02:29
    2008-02-16 12:59:57 56696552 -
    2009-12-02 13:00:00 104549 -
    2009-12-02 20:00:00 79349 +
    

    only the last test date/time lays less than 24 hours in the past.

提交回复
热议问题