I wanted to calculate the difference between two dates in month with PHP but it seems like there is a bug somewhere.
$datetime1 = new DateTime(date('Y-m-d')); $datetime2 = new DateTime(MyObject->getDate()); echo($datetime1->format('d/m/Y')); echo($datetime2->format('d/m/Y)); Result:
29/01/2016 27/01/2015 $dateInterval = $datetime1->diff($datetime2); echo($dateInterval->format(%m months); Result:
0 months Why is that? What am i doing wrong ?
print_r($dateInterval)can help you understand how the classDateIntervalworks.