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
inputcannot be converted into a validDate(as determined by toDateStrict).- When
amountis not a finite number.
- When
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))