PHP Carbon diffInMonths

datetime, php, php-carbon

Solution

$start = \Carbon\Carbon::create(2017, 4, 1);
$end   = \Carbon\Carbon::create(2017, 5, 1);

echo round($start->floatDiffInMonths($end));

Problem

I have a problem with PHP Carbon diffInMonths function. In some cases I got wrong result. For example: ``` $start = \Carbon\Carbon::create(2017, 4, 1); $end = \Carbon\Carbon::create(2017, 5, 1); echo $start->diffInMonths($end); ``` I should get 1 but I got 0. I use PHP 7.1 and Laravel 5.4. Does anybody have a same issue? How can I fix it? Thank you for your help!

Original source

Related problems