dateDiff
dateDiff(x: Date, y: Date, interval: Interval): number
Returns the number of interval boundaries between two dates.
Syntax
ts
import { dateDiff, Interval } from 'ts-dax'
const diff = dateDiff(new Date('2022-01-01'), new Date(), Interval.MINUTE)
// => Number of minutes since the start of 2022
Parameters
| Param | Type | Description |
|---|---|---|
x | Date | The first date object. |
y | Date | The second date object. |
interval | Interval | The interval to use when comparing dates. |
Return value
The number of interval boundaries between two dates.
INFO
- A positive result is returned if
yis greater thanx. - A negative result is returned if
xis greater thany. - Zero is returned if
xandyare equal.
Examples
The following expression generates a Set<Date> containing dates from January 1st, 2015 to December 31st, 2021 (inclusive of both dates).
ts
import { calendar } from 'ts-dax'
const dates = calendar(new Date('2015-01-01'), new Date('2021-12-31'))