The offset of the time zone and the time zone are two different things. The time zone may have different offsets if daylight saving time is used. Timezone support was added to SQL Server in the latest version of 2016.
Your question has two parts: how to convert a value datetimeto a value with an offset / time zone, and then how to convert that value to UTC.
In versions prior to SQL Server 2014, you must first determine the correct offset for your local time zone, for example, using C # code. After that, you can convert datetimeto a `datetimeoffset with a special offset with TODATETIMEOFFSET :
select TODATETIMEOFFSET(GETDATE(),'02:00')
or
select TODATETIMEOFFSET(GETDATE(),120)
This will return the value datetimeoffsetwith the original time and the specified offset.
(, UTC) SWITCHOFFSET
select SWITCHOFFSET(@someDateTimeOffset,0)
select SWITCHOFFSET(TODATETIMEOFFSET(GETDATE(),120),0)
. , SomeTime,
select SWITCHOFFSET(TODATETIMEOFFSET(SomeTime,@offsetInMinutes),0)
SQL Server 2016 . , , UTC:
SELECT (getdate() at time zone 'Central Europe Standard Time') AT TIME ZONE 'UTC'
AT TIMEZONE a datetimeoffset +2:00, UTC.
, , datetime datetimeinfo. SQL Server , , .. , - . .NET datetimeoffset, - .