Skip to main content
@spa-tools/utilities

daysDiff()

The daysDiff() function calculates the number of days between two date values where values can be date object, timestamp integer, or date string.

Usage

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

const date1 = new Date('2021-01-01');
const date2 = '2021-01-10';

const diff = daysDiff(date1, date2);
console.log(diff);
// --> 9

Arguments

NameTypeDescription
date1string | number | DateThe first date value to compare
date2string | number | DateThe second date value to compare

Returns

number - The number of days between the two date values.