Time.Hour is a Power Query M function that extracts the hour component from a given time, datetime, or datetimezone value. The function returns the hour component as a number.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Time.Hour( dateTime as any ) as nullable number
Description
Time.Hour extracts the hour component of the provided time, datetime, or datetimezone value, dateTime returns it as a number.
Examples
Let’s look at how to use the Time.Hour function. This function, while categorized under Time functions, can extract the hour value from time, datetime, and datetimezone values.
Extracting Hours from a Time Value
You can extract the hour component from a time value as follows:
// Output: 12
Time.Hour( #time( 12, 10, 0 ) )
In this example, #time( 12, 10, 0 ) represents 12:10 PM. The Time.Hour function extracts the hour value, which is 12.
Extracting Hours from a DateTime Value
When you have a datetime value and you want to extract the hour component from it, you can use the Time.Hour function. Here’s an example:
// Output: 8
Time.Hour( #datetime( 2024, 9, 15, 8, 30, 1 ) )
In this example, #datetime( 2024, 9, 15, 20, 30, 1 ) represents September 15, 2024, at 8:30:01 AM. The Time.Hour function pulls out the hour part from this datetime value, which is 20.
Extracting Hours from a DateTimeZone Value
The function also works with datetimezone values. This means you can extract the hour part from a datetime value that includes time zone information. Here’s how:
// Output: 9
Time.Hour( #datetimezone( 2024, 9, 15, 9, 45, 1, 2, 30 ) )
In this case, #datetimezone( 2024, 9, 15, 9, 45, 1, 2, 30 ) represents September 15, 2024, at 9:45:01 AM with an offset of +2 hours and 30 minutes from UTC. The Time.Hour function extracts the hour part, which is 9.
Related functions
Other functions related to Time.Hour are:
2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy