Skip to main content
@spa-tools/utilities

addMinutes()

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

Usage

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

const date = new Date('2021-01-01');
console.log(date.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '01/01/2021 12:00 AM'

const newDate1 = addMinutes(date, 5);
console.log(newDate1.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '01/01/2021 12:05 AM'

const newDate2 = addMinutes(date, 60);
console.log(newDate2.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '01/01/2021 1:00 AM'

const newDate3 = addMinutes(date, -60);
console.log(newDate3.toLocaleDateString('en-US', { hour: 'numeric', minute: 'numeric' }));
// --> '12/31/2020 11:00 PM'

Arguments

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

Returns

Date - The new date object with the added minutes.