Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
Returns a datetimeoffset value that is translated from a datetime2 expression.
Transact-SQL syntax conventions
TODATETIMEOFFSET ( datetime_expression , timezoneoffset_expression )
datetime_expression
Is an expression that resolves to a datetime2 value.
Note
The expression cannot be of type text, ntext, or image because these types cannot be implicitly converted to varchar or nvarchar.
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
If expression is a character string, it must be in the format {+|-}TZH:THM.
datetimeoffset. The fractional precision is the same as the datetime_expression argument.
The following example changes the zone offset of the current date and time to time zone -07:00
.
DECLARE @todaysDateTime DATETIME2;
SET @todaysDateTime = GETDATE();
SELECT TODATETIMEOFFSET (@todaysDateTime, '-07:00');
-- RETURNS 2019-04-22 16:23:51.7666667 -07:00
The following example changes the current time zone to -120
minutes.
SELECT TODATETIMEOFFSET(SYSDATETIME(), -120)
-- RETURNS: 2019-04-22 11:39:21.6986813 -02:00
The following example adds a 13-hour time zone offset to a date and time.
SELECT TODATETIMEOFFSET(SYSDATETIME(), '+13:00')
-- RETURNS: 2019-04-22 11:39:29.0339301 +13:00
CAST and CONVERT (Transact-SQL)
Date and Time Data Types and Functions (Transact-SQL)
AT TIME ZONE (Transact-SQL)
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today