I'm still learning PHP and trying to improve in PHP programming. So, I'm testing out a simple code that shows the duration between two dates. I test it with different start dates and end dates until this one got the wrong duration.
Code:
<?php
$d1 = new DateTime('2017-02-20'); // 20 Feb 2017
$d2 = new DateTime('2017-05-12'); // 12 May 2017
$diff = $d2->diff($d1); //excluding end date
echo $diff->y ." years ";
echo $diff->m ." months ";
echo $diff->d ." days";
?>
The correct duration was supposed to be 0 years 2 months 22 days. But it displayed the wrong duration that is 0 years 2 months 20 days.
Can someone explain to me why is that? I want to know what is the reason why it became like that.