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