Skip to content

dateDiff

kherP edited this page Jan 2, 2020 · 3 revisions

This utility compares and returns the difference between two dates. To use it, pass the two dates and range to be calculated in.

Example

const date1 = new Date("December 17, 2019");
const date2 = new Date("December 17, 1995");
const result = dateDiff(date1, date2, "year");
console.log(result); // 24

Properties

Param Type Description
firstDate Date First date
secondDate Date Second date to be compared against
range moment.DurationInputArg2 Difference return unit, example: months | seconds | h | m | y
Clone this wiki locally