Level 0 · Your toolkit · Card 5 of 9 · by Kaushik Saha
Work with time
Commands ago · now · between · bin
What these commands do
| Command | What it does | Shape |
|---|---|---|
ago | A moment in the past, counted back from now | TimeGenerated > ago(1h) |
now | The current time | now() |
between | Inside a range, both ends included | Col between (A .. B) |
bin | Rounds times down into buckets, so you can count per hour or per day | bin(TimeGenerated, 1h) |
Times are written like 1h (an hour), 30m, 7d or 90s.
See them work
The sign-ins of the last hour, by the story's clock:
SigninLogs
| where TimeGenerated > ago(1h)
| project TimeGenerated, UserPrincipalName, AppDisplayName
Result on the sample · 6 rows
| TimeGenerated | UserPrincipalName | AppDisplayName |
|---|---|---|
| 2026-06-10 11:32:04 | it.admin@contoso.com | My Apps |
| 2026-06-10 11:47:01 | it.admin@contoso.com | Azure Portal |
| 2026-06-10 11:02:40 | sara.lind@contoso.com | Office 365 Exchange Online |
| 2026-06-10 11:12:27 | it.admin@contoso.com | Office 365 SharePoint Online |
| 2026-06-10 11:06:28 | it.admin@contoso.com | Office 365 Exchange Online |
| 2026-06-10 11:02:00 | sara.lind@contoso.com | Office 365 Exchange Online |
now() is the current time, so this is the same as "the last 30 minutes":
SigninLogs
| where TimeGenerated > now() - 30m
| project TimeGenerated, UserPrincipalName, AppDisplayName
Result on the sample · 2 rows
| TimeGenerated | UserPrincipalName | AppDisplayName |
|---|---|---|
| 2026-06-10 11:32:04 | it.admin@contoso.com | My Apps |
| 2026-06-10 11:47:01 | it.admin@contoso.com | Azure Portal |
The seven minutes around Alex's break-in, using between:
SigninLogs
| where TimeGenerated between (datetime(2026-06-10T08:14:00Z) .. datetime(2026-06-10T08:21:00Z))
| project TimeGenerated, UserPrincipalName, IPAddress, ResultType
Result on the sample · 11 rows
| TimeGenerated | UserPrincipalName | IPAddress | ResultType |
|---|---|---|---|
| 2026-06-10 08:19:36 | sara.lind@contoso.com | 192.0.2.20 | 0 |
| 2026-06-10 08:17:05 | alex.morgan@contoso.com | 203.0.113.45 | 50126 |
| 2026-06-10 08:20:36 | alex.morgan@contoso.com | 203.0.113.45 | 0 |
| 2026-06-10 08:19:44 | alex.morgan@contoso.com | 203.0.113.45 | 500121 |
| 2026-06-10 08:15:10 | alex.morgan@contoso.com | 203.0.113.45 | 50126 |
| 2026-06-10 08:14:02 | alex.morgan@contoso.com | 203.0.113.45 | 50126 |
| 2026-06-10 08:19:12 | alex.morgan@contoso.com | 203.0.113.45 | 50126 |
| 2026-06-10 08:15:49 | ben.carter@contoso.com | 192.0.2.20 | 0 |
| 2026-06-10 08:16:31 | alex.morgan@contoso.com | 203.0.113.45 | 50126 |
| 2026-06-10 08:18:41 | alex.morgan@contoso.com | 203.0.113.45 | 50126 |
| 2026-06-10 08:20:09 | alex.morgan@contoso.com | 203.0.113.45 | 500121 |
bin buckets the morning into hours (summarize is the next card):
SigninLogs
| summarize SignIns = count() by bin(TimeGenerated, 1h)
| sort by TimeGenerated asc
Result on the sample · 5 rows
| TimeGenerated | SignIns |
|---|---|
| 2026-06-10 07:00:00 | 18 |
| 2026-06-10 08:00:00 | 51 |
| 2026-06-10 09:00:00 | 46 |
| 2026-06-10 10:00:00 | 20 |
| 2026-06-10 11:00:00 | 6 |
Your turn
Count the sign-ins in each 30-minute bucket, oldest first.
Write it in the box below and check it. Then compare with one answer; others can be right too.
Show one answer
SigninLogs
| summarize SignIns = count() by bin(TimeGenerated, 30m)
| sort by TimeGenerated asc
Result on the sample · 9 rows
| TimeGenerated | SignIns |
|---|---|
| 2026-06-10 07:30:00 | 18 |
| 2026-06-10 08:00:00 | 30 |
| 2026-06-10 08:30:00 | 21 |
| 2026-06-10 09:00:00 | 23 |
| 2026-06-10 09:30:00 | 23 |
| 2026-06-10 10:00:00 | 19 |
| 2026-06-10 10:30:00 | 1 |
| 2026-06-10 11:00:00 | 4 |
| 2026-06-10 11:30:00 | 2 |
Check your own query
Write your query for the task above and check it against the real schema.
All data on this page is sample data, made up for this course. The IP addresses come from ranges reserved for documentation, and the people and the company are fictional.
Card by Kaushik Saha. Every query checked with Microsoft.Azure.Kusto.Language 12.4.1 against schema bundle 2026.10.29; every result computed on the course's sample with Kusto-Loco 1.4.9, an open-source KQL engine (credits). The story's clock reads 12:00 UTC on 10 June 2026.