How to compare two dates in php

前端 未结 15 2692
臣服心动
臣服心动 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条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 09:22

    Guys Please don't make it so complex The simple answer bellow

    $date1=date('d_m_y');
    $date2='31_12_11';
    $date1=str_replace('_', '-', $date1);
    $date2=str_replace('_', '-', $date2)
    if(strtotime($date1) < strtotime($date2))
       echo '1 is small ='.strtotime($date1).','.$date1;
    else
       echo '2 is small ='.strtotime($date2).','.$date2;
    

    I just have added two more lines with your code

提交回复
热议问题