How to compare two dates in php

前端 未结 15 2597
臣服心动
臣服心动 2020-11-22 08:37

How to compare two dates in php if dates are in format \'03_01_12\' and \'31_12_11\' .

I am using this code:

$date1=date(\'         


        
15条回答
  •  梦如初夏
    2020-11-22 09:11

    Not answering the OPs actual problem, but answering just the title. Since this is the top result for "comparing dates in php".

    Pretty simple to use Datetime Objects (php >= 5.3.0) and Compare them directly

    $date1 = new DateTime("2009-10-11");
    $date2 = new DateTime("tomorrow"); // Can use date/string just like strtotime.
    var_dump($date1 < $date2);
    

提交回复
热议问题