How to Compare Two Date with Time in Php

前端 未结 2 1598
醉酒成梦
醉酒成梦 2021-01-29 12:04

I Need To Compare Two Date Time Variable in Php for my project what is the best way to compare

$date1 = \"2018-02-06 15:09:44\";
$date2 = \"2018-02-06 16:09:44\         


        
2条回答
  •  时光取名叫无心
    2021-01-29 12:51

    $date1 = new DateTime("2018-02-06 15:09:44");
    $date2 = new DateTime("2018-02-06 16:09:44");
    
    if($date1 > $date2 ) {
    // statement
    }else {
    // other statement
    }
    

提交回复
热议问题