Diff in months with Carbon

50 Views Asked by At

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));

1

There are 1 best solutions below

0
Zaid Malek On BEST ANSWER

Try this:

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