Datetime Diff

datetime_diff

Calculates the difference between two datetime values in the specified units.

Spec

datetime_diff(part, datetime1, datetime2)

Parameters

part - The unit: "year", "month", "day", "hour", "minute", "second", "millisecond".
datetime1 - The first datetime value.
datetime2 - The second datetime value.

Return Value

An int64: the difference (datetime1 - datetime2) in the specified units.

Example

datatable(a:datetime, b:datetime)[datetime(2024-01-03), datetime(2024-01-01)]
| extend diff = datetime_diff("day", a, b)
abdiff
2024-01-03T00:00:00.0000000Z2024-01-01T00:00:00.0000000Z2