The SWITCHOFFSET function returns a datetimeoffset value that has been altered from the stored time zone offset to a new time zone offset that has been given.
Syntax: SWITCHOFFSET ( datetimeoffset_expression, timezoneoffset_expression )
Example:
SELECT SWITCHOFFSET (GETDATE(), ‘-04:00’)
Returns: 2022-02-20 09:16:10.993 -04:00
The following workaround, on the other hand, takes the same amount of time. However the output format is different. It doesn’t include the offset.
SELECT DATEADD(HOUR,-4, GETDATE())
Returns: 2022-02-20 09:16:10.993
Hope this helps.
2 comments