How can I compare two dates in PHP?

前端 未结 13 2018
一整个雨季
一整个雨季 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:59

    This works because of PHP's string comparison logic. Simply you can check...

    if ($startdate < $date) {// do something} 
    if ($startdate > $date) {// do something}
    

    Both dates must be in the same format. Digits need to be zero-padded to the left and ordered from most significant to least significant. Y-m-d and Y-m-d H:i:s satisfy these conditions.

    0 讨论(0)
提交回复
热议问题