Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.
Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.
// CommonJS
var sub = require('date-fns/sub')
// ES 2015 import sub from 'date-fns/sub'
// ESM
import { sub } from 'date-fns'
sub(date, duration)
| Name | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
the date to be changed |
||||||||||||||||
duration |
the object with years, months, weeks, days, hours, minutes and seconds to be subtracted
All values default to 0 |
| Description |
|---|
|
the new date with the seconds subtracted |
| Type | Description |
|---|---|
TypeError |
2 arguments required |
// Subtract the following duration from 15 June 2017 15:29:20
const result = sub(new Date(2017, 5, 15, 15, 29, 20), {
years: 2,
months: 9,
weeks: 1,
days: 7,
hours: 5,
minutes: 9,
seconds: 30
})
//=> Mon Sep 1 2014 10:19:50
© 2021 Sasha Koss and Lesha Koss
Licensed under the MIT License.
https://date-fns.org/v2.29.2/docs/sub