Skip to main content
@spa-tools/utilities

addDays()

The addDays() function adds a number of days to a given date object, timestamp integer, or date string.

Usage

import { addDays } from '@spa-tools/utilities';

const date = new Date('2021-01-01');

const newDate1 = addDays(date, 5);
console.log(newDate1.toLocaleDateString('en-US'));
// --> '01/06/2021'

const newDate2 = addDays(date.getTime(), 6);
console.log(newDate2.toLocaleDateString('en-US'));
// --> '01/07/2021'

const newDate3 = addDays('2021-01-01', 7);
console.log(newDate3.toLocaleDateString('en-US'));
// --> '01/08/2021'

Arguments

NameTypeRequired?Description
datestring | number | DateyesThe date value to add days to as either date string, timestamp integer, or date object
daysnumberyesThe number of days to add

Returns

Date - The new date object with the added days.