Menu

SQL Server ODBC SECOND() Scalar Function

Updated on

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

ODBC syntax

SELECT {fn SECOND(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 SECOND(@value)} AS second_value;

The result is 45.

Native T-SQL alternative

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

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

SELECT DATEPART(second, @value) AS second_value;

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