HOUR Function - SQL


Overview


The HOUR function in SQL extracts the hour part from a time or datetime expression. It is useful for retrieving the hour component of a time.

Example:

SELECT HOUR('2000-01-01 07:12:33')

Syntax:

SELECT HOUR(time)

time is the time or datetime from which you want to extract the hour.


Example: Time Hard-coded value


In this example, we are returning the hour for the time ‘07:12:33,’ for a final output of 7.


Example: Datetime Hard-coded value


In this example, we are returning the hour for the datetime ‘2000-01-01 07:12:33,’ for a final output of 7.