How do I compare two DateTime objects in PHP 5.2.8?

后端 未结 7 1966
伪装坚强ぢ
伪装坚强ぢ 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:47

    $elapsed = '2592000';
    // Time in the past
    $time_past = '2014-07-16 11:35:33';
    $time_past = strtotime($time_past);
    
    // Add a month to that time
    $time_past = $time_past + $elapsed;
    
    // Time NOW
    $time_now = time();
    
    // Check if its been a month since time past
    if($time_past > $time_now){
        echo 'Hasnt been a month';    
    }else{
        echo 'Been longer than a month';
    }
    

提交回复
热议问题