datetime and timespan

Kusto has two time types:

  • datetime: a point in time, always UTC. Columns such as TimeGenerated have this type.
  • timespan: a duration, such as 5 minutes or 2 days.

Writing them

A date is written datetime(...): datetime(2026-06-14) is midnight at the start of that day; datetime(2026-06-14 08:30) and datetime(2026-06-14T08:30:00Z) add a time.

A time span is a number with a unit: 2d (days), 6h (hours), 30m (minutes), 10s (seconds), 100ms (milliseconds). Results show spans as days.hours:minutes:seconds, so 1d + 2h appears as 1.02:00:00.

Date math

Expression Result
datetime + timespan a datetime (later)
datetime - timespan a datetime (earlier)
datetime - datetime a timespan
timespan / timespan a number, e.g. Duration / 1h = hours

Comparisons work as you would expect: TimeGenerated > datetime(2026-06-14).

datetime_part()

datetime_part("hour", TimeGenerated) returns one part of a date as a number. Parts include year, month, day, hour, minute, second, dayofyear and week_of_year. Useful for “sign-ins outside office hours” (remember: the hour is UTC).

To round times down to an interval for grouping, use bin(). For times relative to now, use ago().

Examples

1 Audit events in a time window
AuditLogs
| where TimeGenerated between (datetime(2026-06-12 08:00) .. datetime(2026-06-12 18:00))
| project TimeGenerated, OperationName, Identity
2 Subtracting two times gives a time span
SecurityEvent
| summarize First = min(TimeGenerated), Last = max(TimeGenerated) by Computer
| extend Span = Last - First, Days = (Last - First) / 1d

Dividing a time span by 1d gives the number of days as a decimal number.

3 Time span literals and arithmetic
print OneDay = 1d, TwoHours = 2h, HalfHour = 30m, TenSeconds = 10s, Sum = 1d + 2h, HoursPerDay = 1d / 1h

Practice it