CONVERT(DATETIMEOFFSET
-- assuming all servers are on CEST time
,@dt AT TIME ZONE 'Central European Standard Time'
AT TIME ZONE 'UTC')
If you’re stuck on a lower version of SQL Server, I’d suggest you upgrade 🙂 Or maybe create a table with all the start and end dates of daylight savings time for each year, so you can easily look up the offset.
UPDATE:
Turns out the conversion to DATETIMEOFFSET isn’t even necessary, which makes the code even shorter:
DECLARE @dt DATETIME = '2020-02-22 22:23:13.920';
SELECT CONVERT(DATETIME,
@dt AT TIME ZONE 'Central European Standard Time'
AT TIME ZONE 'UTC');
Hello, Great post. We have a situation where we the timezone can be different for our clients. In that case how can we convert to UTC? is there a way around? Thanks in advance.