HOUR is a date-time extraction keyword or function that isolates the hour portion of a temporal value. In ANSI/Standard SQL it appears inside the EXTRACT clause (EXTRACT(HOUR FROM expr)). MySQL exposes it as a standalone scalar function (HOUR(expr)), SQL Server and Oracle use DATEPART(hour, expr), while PostgreSQL offers both EXTRACT and the date_part('hour', expr) helper. The result is an integer between 0 and 23. If the input is NULL, the result is NULL. Fractional seconds are ignored. For timestamp values with time zone, most engines first convert to the session time zone before extracting. HOUR is immutable and deterministic and can be used in SELECT lists, WHERE filters, GROUP BY, ORDER BY, window functions, and index definitions. Because it returns only the hour, it is often paired with other date parts or wrapped in DATE_TRUNC when higher precision is unnecessary.
DATETIME
(TIMESTAMP) - TIME Temporal expression from which to extract the hourEXTRACT, MINUTE, SECOND, DATEPART, DATE_TRUNC, TIMESTAMP
SQL:1999
0 through 23 in 24-hour format.
Yes – given the same input and session time zone, it always returns the same result.
Only if the database implicitly casts DATE to TIMESTAMP or if you cast it manually; otherwise you will get an error.
Invoke EXTRACT separately for each part or use DATE_TRUNC to zero out smaller units.