Time.StartOfHour
TimeReturns the first moment of the hour for the given time or datetime value.
Syntax
Time.StartOfHour(dateTime as any) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
dateTime | any | Yes | A time, datetime, or datetimezone value. |
Return Value
any — A time, datetime, or datetimezone value representing XX:00:00.
Remarks
Time.StartOfHour returns the first instant of the clock hour containing the input value: XX:00:00. When passed a plain time, it returns a time with minutes and seconds set to zero. When passed a datetime or datetimezone, it returns the same type with only the time component adjusted — the date and any timezone offset are preserved unchanged. This is useful for bucketing events into hourly groups or building inclusive hourly range filters.
Pair Time.StartOfHour with Time.EndOfHour using the same input to construct a complete inclusive hourly boundary: [EventTime] >= Time.StartOfHour(ref) and [EventTime] <= Time.EndOfHour(ref). Use Time.StartOfHour as the grouping key for hourly aggregations — group by Time.StartOfHour([Timestamp]) to bucket all events into their clock hour.
For truncating a datetime to midnight (start of day) rather than the start of an hour, use Date.StartOfDay instead.
Examples
Example 1: Truncate log timestamps to the hour
Table.AddColumn(
Table.SelectColumns(Table.FirstN(OrderLog, 4), {"LogID", "Timestamp"}),
"HourStart", each Time.StartOfHour([Timestamp]), type datetime
)LogID | Timestamp | HourStart | |
|---|---|---|---|
| 1 | L001 | 1/15/2024 9:30:00 AM | 1/15/2024 9:00:00 AM |
| 2 | L002 | 1/16/2024 2:15:00 PM | 1/16/2024 2:00:00 PM |
| 3 | L003 | 1/18/2024 11:00:00 AM | 1/18/2024 11:00:00 AM |
| 4 | L004 | 1/20/2024 8:45:00 AM | 1/20/2024 8:00:00 AM |
Example 2: Start of hour for a specific time
#table(
type table [Result = time],
{{Time.StartOfHour(#time(14, 30, 45))}}
)Result | |
|---|---|
| 1 | 14:00:00 |
Example 3: Group log entries by clock hour
Table.Group(
Table.AddColumn(OrderLog, "HourStart", each Time.StartOfHour([Timestamp]), type datetime),
{"HourStart"},
{{"EventCount", each Table.RowCount(_), Int64.Type}}
)HourStart | EventCount | |
|---|---|---|
| 1 | 1/15/2024 9:00:00 AM | 1 |
| 2 | 1/16/2024 2:00:00 PM | 1 |
| 3 | 1/18/2024 11:00:00 AM | 1 |
| 4 | 1/20/2024 8:00:00 AM | 1 |
| 5 | 2/1/2024 4:00:00 PM | 1 |
| 6 | 2/2/2024 10:00:00 AM | 1 |
| 7 | 2/10/2024 1:00:00 PM | 1 |
| 8 | 2/12/2024 9:00:00 AM | 1 |