Subtract the specified number of years from the given date.
Subtract the specified number of years from the given date.
// CommonJS
var subYears = require('date-fns/subYears')
// ES 2015 import subYears from 'date-fns/subYears'
// ESM
import { subYears } from 'date-fns'
subYears(date, amount)
| Name | Description |
|---|---|
date |
the date to be changed |
amount |
the amount of years to be subtracted. Positive decimals will be rounded using |
| Description |
|---|
|
the new date with the years subtracted |
| Type | Description |
|---|---|
TypeError |
2 arguments required |
// Subtract 5 years from 1 September 2014: const result = subYears(new Date(2014, 8, 1), 5) //=> Tue Sep 01 2009 00:00:00
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/subYears