How do I compare two DateTime objects in PHP 5.2.8?

后端 未结 7 1956
伪装坚强ぢ
伪装坚强ぢ 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 18:08

    This may help you.

    $today = date("m-d-Y H:i:s");
    $thisMonth =date("m");
    $thisYear = date("y");
    $expectedDate = ($thisMonth+1)."-08-$thisYear 23:58:00";
    
    
    if (strtotime($expectedDate) > strtotime($today)) {
        echo "Expected date is greater then current date";
        return ;
    } else
    {
     echo "Expected date is lesser then current date";
    }
    
    0 讨论(0)
提交回复
热议问题