getDiff

Commons
stable

Computes the difference between two dates in the requested unit (years, quarters, months, weeks, days, hours, minutes, seconds). Falls back to milliseconds when no unit is supplied.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

date
required
Date
The reference (start) date.
comparing
required
Date | string
The date to compare against. Strings are parsed via new Date().
unit
string
One of "years" | "quarters" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds". Omit for milliseconds.

API

Return value

The value returned by this util.

The signed integer (or millisecond float) difference. Positive when date is after comparing.

Usage

Examples

Ready-to-paste usage snippets.

Diff in days and months

typescript