Menu

SQL Server ODBC HOUR() Scalar Function

Updated on

SQL Server does not provide a bare native T-SQL HOUR() function. It supports HOUR as an ODBC scalar function inside an ODBC escape sequence: {fn HOUR(time_exp)}. Microsoft documents this function as returning an integer from 0 to 23. See ODBC scalar functions in Transact-SQL.

ODBC syntax

SELECT {fn HOUR(time_exp)};

For example, SQL Server can interpret the ODBC escape form in a Transact-SQL statement:

DECLARE @value datetime2 = '2026-09-28T15:30:45';

SELECT {fn HOUR(@value)} AS hour_value;

The result is 15.

Native T-SQL alternative

For ordinary T-SQL, extract the hour with DATEPART:

DECLARE @value datetime2 = '2026-09-28T15:30:45';

SELECT DATEPART(hour, @value) AS hour_value;

See the SQL Server DATEPART() reference for supported date parts and examples.