How can I compare two dates in PHP?

前端 未结 13 2257
一整个雨季
一整个雨季 2020-11-22 06:02

How can I compare two dates in PHP?

The date is stored in the database in the following format

2011-10-2

If I wanted to

13条回答
  •  不知归路
    2020-11-22 06:51

    I would'nt do this with PHP. A database should know, what day is today.( use MySQL->NOW() for example ), so it will be very easy to compare within the Query and return the result, without any problems depending on the used Date-Types

    SELECT IF(expireDate < NOW(),TRUE,FALSE) as isExpired FROM tableName
    

提交回复
热议问题