TODATETIMEOFFSET#
Returns a datetimeoffset value that is translated from a datetime2 expression.
Syntax#
TODATETIMEOFFSET ( datetime_expression, timezoneoffset_expression )
Arguments#
datetime_expression
Is an expression that resolves to a datetime2 value.
timezoneoffset_expression
Is an expression that represents the time zone offset in minutes (if an integer), for example -120, or hours and minutes (if a string), for example ‘+13:00’. The range is +14 to -14 (in hours). The expression is interpreted in local time for the specified timezoneoffset_expression.
Note
The expression cannot be of type text, ntext, or image because these types cannot be implicitly converted to varchar or nvarchar.
Return types#
datetimeoffset. The fractional precision is the same as the datetime_expression argument.
Examples#
Changing the time zone offset of the current date and time
DECLARE @todaysDateTime DATETIME2 = '2025-01-01 21:22:23.1234567'
SELECT TODATETIMEOFFSET (@todaysDateTime, '-07:00');
-- RETURNS 2025-01-01 21:22:23.1234567 -07:00