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.
API
Parameters
Input parameters accepted by this util.
- daterequiredDate
- The reference (start) date.
- comparingrequiredDate | string
- The date to compare against. Strings are parsed via new Date().
- unitstring
- 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