The Time.Hour function in Power Query gives you the hour part of a time or a date and time, as a number from 0 to 23. So 2:35 PM gives you 14, and 9:15 AM gives you 9.
Pulling out the hour is handy when you want to see what happens at what time of day, like the busiest hour for orders or which shift a record belongs to.
In this article, I’ll show you how it works with simple values, table columns, text times, and time zones.
Follow along with the example file
Time.Hour Function Examples.xlsx
Time.Hour Function Syntax
Time.Hour(dateTime as any) as nullable number
- dateTime – the value you want the hour from. It can be a time, a datetime (a date with a time), or a datetimezone (a date and time with a time zone offset).
What it returns – the hour as a whole number from 0 to 23, using the 24-hour clock. If the value is null, you get null.
Text, plain numbers, durations, and date-only values aren’t accepted. For any of these, Time.Hour returns the error “The Time value must contain the Time component.”
The Time.Hour function is part of the Power Query M language, so it works wherever Power Query does in Excel: Excel 365, 2024, 2021, 2019, and 2016 for Windows, and Excel for Microsoft 365 on Mac.
When to Use the Time.Hour Function
Use this function when you need to:
- Add an hour column to a table of timestamps, like order or entry times
- Count or total records by hour of the day to find the busiest hours
- Round times down to hourly slots for reporting
- Label each row with a shift or time-of-day bucket
- Filter rows that fall inside or outside business hours
- Get the hour from times that came in as text, such as from a CSV file
Example 1: Get the Hour From a Time
Let’s start with a simple one. Suppose you have the time 2:35:20 PM, and you want just the hour.
In Excel, go to Data > Get Data > From Other Sources > Blank Query. In the Power Query Editor that opens, type this formula in the formula bar:
= Time.Hour(#time(14,35,20))
Result: 14

Here, #time(14,35,20) is how M writes a time (hours, minutes, seconds), so it means 2:35:20 PM. Time.Hour returns the hour part, which is 14.
The hour always comes from the 24-hour clock. So any time after noon gives you a number from 12 to 23, not 1 to 11.
Example 2: Get the Hour From a Date and Time
Time.Hour works the same way when the value also has a date. Suppose you have a timestamp of November 6, 2026 at 12:15 AM, just after midnight, and you want its hour.
Create a new blank query the same way as in Example 1, and use this formula:
= Time.Hour(#datetime(2026,11,6,0,15,0))
Result: 0

Here, #datetime(2026,11,6,0,15,0) is a date and time (year, month, day, hours, minutes, seconds). Time.Hour ignores the date and returns the hour, which is 0.
Anything between midnight and 12:59 AM is hour 0, not 12 or 24. Keep that in mind when you build hour ranges, as in Example 6.
Example 3: Add an Hour Column to a Table
This is the most common way you’ll use Time.Hour. Below is a FoodTruckOrders table with the date and time each order was placed, and I want the hour of each order in a new Hour column.

To follow along, select any cell in the FoodTruckOrders table and go to Data > From Table/Range. This opens the table in the Power Query Editor, where the Source step holds it.
If Power Query adds a Changed Type step too, you can delete it, because the formulas in this article work from the Source step. Power Query still reads the Ordered At cells as date and time values.
Add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.AddColumn(Source,"Hour",each Time.Hour([Ordered At]),Int64.Type)
Result: A new Hour column with 11, 12, 12, 12, 13, 17, 18, and 19.

Here, the Table.AddColumn function adds an Hour column and runs Time.Hour([Ordered At]) once for every row. The order placed at 11:42 AM gets 11, and the one at 5:36 PM gets 17.
The Int64.Type at the end gives the new column a Whole Number type. Without it, the column has no type, and you’d see ABC123 in its header.
Example 4: Round Times Down to Hourly Time Slots
In a report, a slot like 9:00 AM reads better than a bare 9. Below is a ClinicArrivals table with the date and time each patient arrived, and I want each arrival’s hourly slot in a new Time Slot column.

Load the ClinicArrivals table into Power Query the same way as in Example 3 (Data > From Table/Range). Then add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.AddColumn(Source,"Time Slot",each #time(Time.Hour([Arrived At]),0,0),type time)
Result: A new Time Slot column with 8:00:00 AM, 8:00:00 AM, 9:00:00 AM, 9:00:00 AM, 10:00:00 AM, and 11:00:00 AM.

Here, Time.Hour([Arrived At]) gets the hour of each arrival, and #time(...,0,0) builds a new time from that hour with zero minutes and seconds. So 9:52 AM becomes 9:00:00 AM.
The type time at the end makes Time Slot a time column. That way, it sorts in time order and loads into Excel as real times you can format.
If you’d rather keep the date in the slot, use the Time.StartOfHour function instead. Time.StartOfHour([Arrived At]) turns 11/16/2026 9:52 AM into 11/16/2026 9:00:00 AM.
Example 5: Count Records by Hour
Now let’s find the busiest hour. Below is a GarageEntries table with the time each car entered a parking garage, and I want the number of entries in each hour.

Load the GarageEntries table into Power Query the same way as in Example 3 (Data > From Table/Range). This one takes two steps.
First, add a new step (by clicking on the fx icon next to the formula bar) and use this formula to add an Hour column:
= Table.AddColumn(Source,"Hour",each Time.Hour([Entry Time]),Int64.Type)
Power Query names this new step Custom1. Right-click it in the Applied Steps pane, choose Rename, and name it Added Hour, because the next formula refers to the step by that name.
Then add one more step and use this formula to count the rows in each hour:
= Table.Group(#"Added Hour",{"Hour"},{{"Entries",each Table.RowCount(_),Int64.Type}})
Result: One row per hour with its Entries count (hour 7 has 2, hour 8 has 4, hour 9 has 2, and hour 10 has 2).

Here, the first step adds the hour of each entry. The Table.Group function then groups the rows by that Hour column, and Table.RowCount counts the rows in each group.
In Table.RowCount(_), the underscore stands for the rows of one group, like all the entries in hour 8. So it counts how many cars came in during that hour.
Hour 8 has the most entries (four cars between 8:05 AM and 8:52 AM), so 8 AM to 9 AM is the busiest hour.
If you’d rather click than type, select the Hour column and use Home > Group By with the Count Rows operation. It writes a similar Table.Group step for you, with the count column named Count.
Example 6: Label Each Row by Shift
Time.Hour is also handy for putting rows into time-of-day buckets. Below is a WarehousePicks table with the date and time each order was picked, and I want the shift each pick happened in, in a new Shift column.

The warehouse runs three shifts. Morning is 6:00 AM to 1:59 PM, Afternoon is 2:00 PM to 9:59 PM, and Night is 10:00 PM to 5:59 AM.
Load the WarehousePicks table into Power Query the same way as in Example 3 (Data > From Table/Range). Then add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.AddColumn(Source,"Shift",each
let h = Time.Hour([Picked At]) in
if h >= 6 and h < 14 then "Morning"
else if h >= 14 and h < 22 then "Afternoon"
else "Night",type text)
Result: A new Shift column with Night, Morning, Morning, Morning, Afternoon, Afternoon, Afternoon, Night, and Night.

Here, let h = Time.Hour([Picked At]) in stores the hour of each pick as h, so the formula doesn’t have to repeat Time.Hour in every condition. The if-then-else checks then pick the shift.
Look at the picks at 1:59 PM and 2:00 PM. The first has hour 13, which is less than 14, so it’s Morning, while the second has hour 14, so it’s Afternoon.
The Night shift crosses midnight, so it can’t be written as one “between” check. That’s why it’s the else part, which catches every hour from 22 to 23 and from 0 to 5.
If a Picked At cell is blank, Time.Hour returns null for it, and the if check can’t compare null with 6. That row shows the error “We cannot convert the value null to type Logical”, so remove or fill blank timestamps before this step.
Example 7: Filter Records Outside Business Hours
This next one comes up a lot with security and activity logs. Below is a BadgeLog table with each employee’s badge time at the office door, and I want to keep only the entries made before 7 AM or from 7 PM onwards.

Load the BadgeLog table into Power Query the same way as in Example 3 (Data > From Table/Range). Then add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.SelectRows(Source,each Time.Hour([Badge Time]) < 7 or Time.Hour([Badge Time]) >= 19)
Result: Four rows are left: Zoe Jones at 6:41 AM, Benjamin Bennett at 7:02 PM, Rachel Anderson at 10:47 PM, and David Carter at 5:58 AM.

Here, the Table.SelectRows function keeps a row only when its badge hour is less than 7 or at least 19. The or means a row needs to meet just one of the two conditions.
Tara Wood’s 6:59 PM entry is dropped because its hour is 18. Zoe Jones’s 7:00 AM entry on the second day is dropped too, because its hour is 7, which isn’t less than 7.
So the hour check works on whole hours. If your cut-off isn’t on the hour, like 6:30 PM, compare the time itself instead, for example Time.From([Badge Time]) >= #time(18,30,0).
Rows with a blank Badge Time don’t cause an error here. Table.SelectRows quietly drops them, because their hour is null and a null condition doesn’t count as a match.
Example 8: Get the Hour From Times Stored as Text
Times often come in as text, especially from CSV files or copied data. Below is a YogaBookings table with each member’s class time stored as text, and I want the hour of each class in a new Hour column.

If you point Time.Hour straight at one of these values, like Time.Hour([Class Time]), every row shows an error. The error says “The Time value must contain the Time component”, because Time.Hour doesn’t read text.
So turn the text into a real time first. Load the YogaBookings table into Power Query the same way as in Example 3, then add a new step (by clicking on the fx icon next to the formula bar) and use this formula:
= Table.AddColumn(Source,"Hour",each Time.Hour(Time.From([Class Time])),Int64.Type)
Result: A new Hour column with 6, 7, 12, 17, 19, and 20.

Here, the Time.From function converts text like “5:45 PM” into a real time value. Time.Hour then gets the hour from it, which is 17.
Notice that “12:00 PM” gives 12, because noon is hour 12 on the 24-hour clock. A class at 12:30 AM would give 0.
Time.From reads the text using your computer’s regional settings. If your settings don’t use AM and PM, tell it the text is in US format with Time.From([Class Time],"en-US").
You can also fix this at the column level. Before you add the Hour step, change the Class Time column’s type to Time (Transform > Data Type), which adds a Changed Type step.
Then add the Hour step on top of it, so it reads the converted times instead of the text in Source. Time.From is no longer needed, and the formula becomes = Table.AddColumn(#"Changed Type","Hour",each Time.Hour([Class Time]),Int64.Type).
Example 9: Get the Hour From a Date and Time With a Time Zone
When a value has a time zone offset, Time.Hour returns the hour as written, in that value’s own time zone. Suppose a support call was logged at 11:30 PM on March 9, 2026, in India (UTC+05:30), and you want its hour.
Create a new blank query the same way as in Example 1, and use this formula:
= Time.Hour(#datetimezone(2026,3,9,23,30,0,5,30))
Result: 23

Here, #datetimezone(2026,3,9,23,30,0,5,30) is a date and time with an offset of +05:30 (the last two numbers are the offset hours and minutes). Time.Hour ignores the offset and returns the local hour, 23.
That’s fine on its own. But if calls come from offices in different time zones, the local hours can’t be compared with each other.
To get every hour in the same time zone, convert the value to UTC first. Use this formula instead:
= Time.Hour(DateTimeZone.ToUtc(#datetimezone(2026,3,9,23,30,0,5,30)))
Result: 18

Here, the DateTimeZone.ToUtc function moves the time back by 5 hours 30 minutes, to 6:00 PM UTC. Time.Hour then returns 18.
Other Excel Articles You May Also Like:
- Duration.From function
- Duration.Hours Function in Power Query M
- DateTime.From – Use DateTime.From in Power Query M to convert values to date and time.
- Date.Day – Use Date.Day in Power Query M to get the day of the month from a date.
- Date.Month – Use Date.Month in Power Query M to get the month number from a date.
- DateTime.FromText – Use DateTime.FromText in Power Query M to convert text to date and time.
- DateTime.LocalNow – Use DateTime.LocalNow in Power Query M to get the current date and time.
- Date.QuarterOfYear – Use Date.QuarterOfYear in Power Query M to get the quarter of a date.