The base date as a Date object or timestamp (number)
The number of days to add (can be negative to subtract)
A new Date object with the days added, or Invalid Date if any input is invalid
// Add positive days
const result = addDays(new Date(2025, 0, 1), 5);
// Returns: 2025-01-06
// Subtract days (negative amount)
const result = addDays(new Date(2025, 0, 10), -3);
// Returns: 2025-01-07
// Works with timestamps
const timestamp = Date.now();
const result = addDays(timestamp, 7);
// Returns: Date 7 days from now
// Fractional amounts are truncated
const result = addDays(new Date(2025, 0, 1), 1.9);
// Returns: 2025-01-02 (1.9 truncated to 1)
// Invalid inputs return Invalid Date
const result = addDays(new Date("invalid"), 5);
// Returns: Invalid Date
const result = addDays(new Date(2025, 0, 1), NaN);
// Returns: Invalid Date
Add the specified number of days to the given date.
This function validates arguments before processing and returns a new Date instance with the specified number of days added. Fractional days are truncated toward zero.