Skip to content
On this page

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

ParamTypeDescription
xDateThe first date object.
yDateThe second date object.
intervalIntervalThe interval to use when comparing dates.

Return value

The number of interval boundaries between two dates.

INFO

  • A positive result is returned if y is greater than x.
  • A negative result is returned if x is greater than y.
  • Zero is returned if x and y are 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'))

Released under the MIT License. Not affiliated with Microsoft.