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