How to Compare Two Date with Time in Php

前端 未结 2 1590
醉酒成梦
醉酒成梦 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:45

     $date1 = "2018-02-06 15:09:44";
     $date2 = "2018-02-06 16:09:44";
    
     if(strtotime($date1) < strtotime($date2)) {
       echo "date1 less than date2";
     } else {
       echo "date1 is greater than date2;
     }
    

提交回复
热议问题