Loading lesson path
provides methods for easy and reliable date and time arithmetic. Add and subtract days, months, years, and time without modifying the original value.
DST bugs and Time Zone problems. JavaScript Temporal Add and Subtract add() returns a temporal object moved forward by a given duration. Syntax temporal.add( duration )
Formula
// Add a duration const newDate = myDate.add({ days: 7 });subtract() returns a temporal object moved backward by a given duration. Syntax temporal.subtract( duration )
Formula
// Subtract a duration const newDate = myDate.subtract({ days: 7 });Adding one day to March 31st is April 1st. Both methods are immutable, returning new Temporal objects.
and subtract() methods accept a duration object as input.
{ months: 2, days: 7, hours: 1 }.years months weeks days hours minutes seconds milliseconds microseconds nanoseconds
You can safely add or subtract time. The original value does not change.
Formula
// Create a PlainDateTime object const date = Temporal.PlainDateTime.from("2026 - 05 - 17T14:30:00");
// Add and subtract time const earlier = dateTime.subtract({ minutes: 30 });const later = dateTime.add({ hours: 2 });method to add days.
// Create a PlainDate object const myDate = Temporal.PlainDate.from('2026-05-17');Formula
// Add a duration const newDate = myDate.add({ days: 7 });The original date is not changed.
to subtract time.
// Create a PlainDate object const myDate = Temporal.PlainDate.from('2026-05-17');Formula
// Subtract a duration const newDate = myDate.subtract({ days: 7 });// Create a PlainDate object const myDate = Temporal.PlainDate.from('2026-05-17');Formula
// Add multiple units const newDate = today.add({ years: 1, months: 2, days: 15 });Temporal automatically handles different month lengths.
const date = Temporal.PlainDate.from("2026-01-31");
const result = date.add({ months: 1 });If the next month has fewer days, Temporal adjusts automatically.
Adding years works correctly, even for leap years.