Skip to main content
@spa-tools/utilities

addWeeks()

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

Usage

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

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

const newDate1 = addWeeks(date, 5);
console.log(newDate1.toLocaleDateString('en-US'));
// --> '02/05/2021'

const newDate2 = addWeeks(date.getTime(), 6);
console.log(newDate2.toLocaleDateString('en-US'));
// --> '02/12/2021'

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

Arguments

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

Returns

Date - The new date object with the added weeks.