Get the number of full months between the given dates.
Get the number of full months between the given dates using trunc as a default rounding method.
// CommonJS
var differenceInMonths = require('date-fns/differenceInMonths')
// ES 2015 import differenceInMonths from 'date-fns/differenceInMonths'
// ESM
import { differenceInMonths } from 'date-fns'
differenceInMonths(dateLeft, dateRight)
| Name | Description |
|---|---|
dateLeft |
the later date |
dateRight |
the earlier date |
| Description |
|---|
|
the number of full months |
| Type | Description |
|---|---|
TypeError |
2 arguments required |
// How many full months are between 31 January 2014 and 1 September 2014? const result = differenceInMonths(new Date(2014, 8, 1), new Date(2014, 0, 31)) //=> 7
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/differenceInMonths