Chris Straw
SHARE:

SQL Server: Convert a date with time to a specific timezone offset

I needed to insert a record into a table with the datetimeoffset with a specific timezone’s offset.

DECLARE @DateTime DATETIME, @DateTimeWithOffset DATETIMEOFFSET

SET @DateTime = '2024-01-08 11:00:00'

SET @DateTimeWithOffset = TODATETIMEOFFSET(@DateTime, DATEPART(tz, (CAST(@DateTime AS DATETIMEOFFSET) AT TIME ZONE 'Eastern Standard Time')));

SELECT @DateTimeWithOffset

Written by

Chris Straw