Get the number of calendar years between the given dates.
Get the number of calendar years between the given dates.
// CommonJS
var differenceInCalendarYears = require('date-fns/differenceInCalendarYears')
// ES 2015 import differenceInCalendarYears from 'date-fns/differenceInCalendarYears'
// ESM
import { differenceInCalendarYears } from 'date-fns'
differenceInCalendarYears(dateLeft, dateRight)
| Name | Description |
|---|---|
dateLeft |
the later date |
dateRight |
the earlier date |
| Description |
|---|
|
the number of calendar years |
| Type | Description |
|---|---|
TypeError |
2 arguments required |
// How many calendar years are between 31 December 2013 and 11 February 2015? const result = differenceInCalendarYears( new Date(2015, 1, 11), new Date(2013, 11, 31) ) //=> 2
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/differenceInCalendarYears