DifferenceInMonths
DifferenceInMonths is a date utility function that returns the number of full months between two dates. It is commonly used in date manipulation libraries such as date-fns and provides a signed integer: positive when the first date is after the second, negative when it is before.
How it works: the function compares the year and month components to establish a base month difference,
Return value: an integer representing the number of full months between the two dates. If the two
Key considerations: differenceInMonths differs from differenceInCalendarMonths. The latter counts calendar month boundaries and ignores the day
Example: differenceInMonths(new Date(2020, 2, 15), new Date(2020, 0, 15)) returns 2.