diff
The result is the first date minus the second, so it is negative when the second is later. Whole units are reported by default; pass float to get the fraction as well.
Milliseconds, seconds, minutes and hours are fixed lengths and are divided out exactly. Days, months and years are counted as whole elapsed units, which is why two hours across midnight is 0 days and not 1.
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The date the interval is measured from. |
|
| The date subtracted from it. |
|
|
|
|
| Keep the fractional part instead of truncating. Fixed-length units only. |
Returns
number — the interval, negative when the second date is later.
Throws
Exception | Condition |
|---|---|
| an argument is not a valid |
Examples
Measuring an interval
See also
Source
This documentation was generated with AI (Claude) from the library's source code.