Skip to content

addDays()

addDays(input, amount): Date

Defined in: utils/date/addSubDays.ts:34

Add a number of calendar days to a date-like value.

This helper:

  • Accepts Date, ISO-like string, or timestamp number.
  • Works in local time and respects month/year rollover.
  • Never mutates the input; it always returns a new Date instance.

Parameters

input

Base date (local time).

string | number | Date

amount

number

Number of calendar days to add. Can be negative. Must be a finite number, otherwise a RangeError is thrown.

Returns

Date

A new Date instance representing input + amount days.

Throws

  • When input cannot be converted into a valid Date (as determined by toDateStrict).
    • When amount is not a finite number.

Example

ts
const d = new Date(2024, 0, 10); // Jan 10, 2024

addDays(d, 5);   // Jan 15, 2024
addDays(d, -1);  // Jan 9, 2024

Released under the MIT License.