Search code examples
phpphp-carbon

Diff in months with Carbon


I try diff in month at 2 dates. var_dump show me 0. But February have 28 days. 28, 29, 30, 31 January + 28 days February more 1 months. Why diff == 0? $d1 = new Carbon('2023-01-29'); $d2 = new Carbon('2023-02-28'); var_dump($d1->diffInMonths($d2));


Solution

  • Try this:

    var_dump(round($d1->floatDiffInMonths($d2)));