To find the difference between two dates, you should use the date_diff () .
$datetime1 = date_create('2016-10-11');
$datetime2 = date_create('2018-10-11');
$interval = date_diff($datetime1, $datetime2);
return $interval->m; // months
The code works fine as long as the difference between dates is less than 12. If it is greater than or equal, $interval->m
returns 0
, however I need it to return the number of months in any case.
Does anyone know of a workaround?