How do I compare two DateTime objects in PHP 5.2.8?

后端 未结 7 2013
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 17:42

Having a look on the PHP documentation, the following two methods of the DateTime object would both seem to solve my problem:

  • DateTime::diff : Get
7条回答
  •  春和景丽
    2020-11-22 17:44

    If you want to compare dates and not time, you could use this:

    $d1->format("Y-m-d") == $d2->format("Y-m-d")
    

提交回复
热议问题