Skip to content

subDays()

subDays(input, amount): Date

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

Subtract a number of calendar days from a date-like value.

This is a small convenience wrapper around addDays, implemented as:

ts
subDays(input, amount) === addDays(input, -amount)

Parameters

input

Base date (local time).

string | number | Date

amount

number

Number of days to subtract. Can be negative.

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

subDays(d, 3);   // Jan 7, 2024
subDays(d, -2);  // Jan 12, 2024 (equivalent to addDays(d, 2))

Released under the MIT License.