How to compare two dates in php

前端 未结 15 2593
臣服心动
臣服心动 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:34

    You can to converte for integer number and compare.

    Eg.:

    $date_1 = date('Ymd');
    $date_2 = '31_12_2011';
    
    $date_2 = (int) implode(array_reverse(explode("_", $date_2)));
    
    echo ($date_1 < $date_2) ? '$date_2 is bigger then $date_1' : '$date_2 is smaller than $date_1';
    

提交回复
热议问题