添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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');

Thanks to Adam for pointing it out!

------------------------------------------------ Do you like this blog post? You can thank me by buying me a beer 🙂

Thanks for this useful information. So the CONVERT is also not needed! No data types are being converted to or from DATETIME here 🙂 This is exactly the same, and simpler:

DECLARE @dt DATETIME = ‘2020-02-22 22:23:13.920’;
SELECT @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.

I guess in that case you’ll need to determine the timezone for the current user and pass it as a parameter?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *