I was doing tests with this function, but it returns an incorrect difference, how do I get around this?
Example: when compared the difference between 01/01 and 01/03 returns the difference of one month, and only when it is 03/03 to return the two months.
Correct:
$datetime1 = new DateTime('2009-01-01');
$datetime2 = new DateTime('2009-03-04');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
echo $interval->format('%R%m month');
Result:
+62 days + 2 month
Incorrect:
$datetime1 = new DateTime('2009-01-01');
$datetime2 = new DateTime('2009-03-01');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
echo $interval->format('%R%m month');
Result:
+59 days + 1 month