Why does DateTime::diff return 0 days between these dates?

前端 未结 1 665
不思量自难忘°
不思量自难忘° 2021-01-21 05:36

Consider the following test case:

$start = new DateTime(\"2011-02-25\");
$end = new DateTime(\"2011-03-25\");

$interval = $end->diff($start);


echo \"INTERV         


        
相关标签:
1条回答
  • 2021-01-21 06:00

    you need to use format code 'a'. d is the number of days in the diff, not the net number of days. in the dateinterval object, days is the corresponding field. in your example, you will see m = 1

    0 讨论(0)
提交回复
热议问题