How to compare two dates in php

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

    Don't know what your problem is but:

    function date_compare($d1, $d2)
    {
        $d1 = explode('_', $d1);
        $d2 = explode('_', $d2);
        
        $d1 = array_reverse($d1);
        $d2 = array_reverse($d2);
        
        if (strtotime(implode('-', $d1)) > strtotime(implode('-', $d2)))
        {
            return $d2;
        }
        else
        {
            return $d1;
        }
    }
    

提交回复
热议问题