Menu

SQL Server TODATETIMEOFFSET() Function

Updated on

TODATETIMEOFFSET(expression, time_zone) converts a date/time expression to datetimeoffset by interpreting the expression as local time at the supplied offset. It attaches the offset without shifting the clock value. Use it when the offset is already known; it does not look up a named time zone or apply its daylight-saving rules. See Microsoft’s TODATETIMEOFFSET reference.

Syntax

TODATETIMEOFFSET(expression, time_zone)

time_zone can be a string offset such as '-05:00' or an integer number of offset minutes, such as -300.

Attach a known offset

This example treats 10:00 as local time at UTC-05:00. The returned clock time remains 10:00; the result now includes the offset:

DECLARE @local_time datetime2(0) = '2022-03-10T10:00:00';

SELECT TODATETIMEOFFSET(@local_time, '-05:00') AS local_value;

Result:

2022-03-10 10:00:00 -05:00

To convert a value through a named time zone with daylight-saving rules, use AT TIME ZONE. To display an existing datetimeoffset value with another numeric offset while preserving the same UTC instant, use SWITCHOFFSET().