How to compare two dates in php

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

    you can try something like:

            $date1 = date_create('2014-1-23'); // format of yyyy-mm-dd
            $date2 = date_create('2014-2-3'); // format of yyyy-mm-dd
            $dateDiff = date_diff($date1, $date2);
            var_dump($dateDiff);
    

    You can then access the difference in days like this $dateDiff->d;

提交回复
热议问题