Date/Since
1.38.0addDays
Returns a new Date with a specified number of days added to the given date without modifying the original Date object.
addDays(date, amount):DateParameters
dateDaterequiredThe date to which the specified number of days will be added.
amountnumberrequiredThe number of days to add to the date. Negative values subtract days.
Returns
DateA new Date object with the specified number of days added.
Examples
01
Basic usage
Add days to a Date object.
TypeScript
import { addDays } from "@cyref/js";
const date = new Date("2026-01-10");
const result = addDays(date, 5);
console.log(result);
// 2026-01-1502
Subtract days
Negative values can be used to subtract days from the date.
TypeScript
import { addDays } from "@cyref/js";
const date = new Date("2026-01-10");
const result = addDays(date, -3);
console.log(result);
// 2026-01-0703
Crossing month boundaries
The function automatically handles dates that move into the next or previous month.
TypeScript
import { addDays } from "@cyref/js";
const date = new Date("2026-01-30");
const result = addDays(date, 3);
console.log(result);
// 2026-02-0204
Original date remains unchanged
addDays creates a new Date object, so the original date is not modified.
TypeScript
import { addDays } from "@cyref/js";
const date = new Date("2026-05-10");
const result = addDays(date, 7);
console.log(date);
// 2026-05-10
console.log(result);
// 2026-05-1705
Adding zero days
Adding zero days returns a new Date with the same date value.
TypeScript
import { addDays } from "@cyref/js";
const date = new Date("2026-06-15");
const result = addDays(date, 0);
console.log(result);
// 2026-06-15Built with@cyref/js·Official documentation