TODATETIMEOFFSET (Transact-SQL)
Returns a datetimeoffset value that is translated from a datetime2 expression.
Syntax
TODATETIMEOFFSET (expression,time_zone)
Arguments
Return Type
datetimeoffset . The fractional precision is the same as the datetime argument.
Examples
A. Changing the time zone offset of the current date and time
The following example changes the zone offset of the current date and time to time zone -07:00.
DECLARE @todaysDateTime Datetime2 SELECT @todaysDateTime = GetDate(); SELECT TODATETIMEOFFSET (@todaysDateTime, '-07:00') -- RETURNS 2007-08-30 15:51:34.7030000 -07:00
B. Changing the time zone offset in minutes
The following example changes the current time zone to -120 minutes.
DECLARE @todaysDate Datetime2 SELECT @todaysDate = GetDate(); SELECT TODATETIMEOFFSET (@todaysDate, -120) -- RETURNS 2007-08-30 15:52:37.8770000 -02:00
C. Adding a 13-hour time zone offset
The following example adds a 13-hour time zone offset to a date and time.
DECLARE @dateTime datetimeoffset(7)= '2007-08-28 18:00:30' SELECT TODATETIMEOFFSET (@dateTime, '+13:00') -- RETURNS 2007-08-28 18:00:30.0000000 +13:00
See Also

Note