HOUR
Description
The HOUR function is used to extract the hour part from a given timestamp type expression. This function is very useful for handling time data and calculating time intervals.
Syntax
Parameters
- timestamp_ltz: Represents a timestamp type expression from which the hour part is to be extracted.
Return Result
Returns an integer representing the hour part of the input expression.
Usage Example
- Extract the hour part from the current timestamp:
This will return the hour part of the current time.
- Extract the hour part from the specified timestamp:
This will return 10, indicating the hour part of the specified time.
- Extract the hour part from a table containing timestamps:
Suppose we have a table named
orders
that contains a column namedorder_time
of type timestamp. We can extract the hour part of each order as follows:
This will return the ID and hour part of each order in the orders
table.
- Use in combination with other time functions:
This will return the ID, hour part, day, and month of each order in the orders
table.