I'm trying to use DateTime->diff to get the number of months between two dates. The problem is I cant understand how works this function. Try this examples, notice that i'm adding one month every output:
$datetime1 = new DateTime('2013-01-01');
$datetime2 = new DateTime('2013-01-01');
$interval = $datetime1->diff($datetime2);
echo $interval->m
Output is 0.
$datetime1 = new DateTime('2013-01-01');
$datetime2 = new DateTime('2013-02-01');
$interval = $datetime1->diff($datetime2);
echo $interval->m
Output is 1.
$datetime1 = new DateTime('2013-01-01');
$datetime2 = new DateTime('2013-03-01');
$interval = $datetime1->diff($datetime2);
echo $interval->m
Output is... 1??? How is this possible?? Month is March, not February. Same error happens in months 6-7
EDIT: Note this question ISNT about February cause this happens in months 6-7
Thanks for you attention.