How to update data in sql server from local to universal time

I have stored date time in local time and I need to convert them all to Universal time.

How to do this in SQL Server 2008?

In local time, I mean either BST or GMT.

i.e. I kept DateTime.Now() from .NET for a year, and now I need to homogenize the data.

Thanks!

+4
source share
2 answers

consider sending already with c # utc

also exists SELECT GETUTCDATE()

in sql server

http://msdn.microsoft.com/en-us/library/ms178635.aspx

change

if you need to update it

 UPDATE SomeTable SET DateTimeStamp = DATEADD(hh, DATEDIFF(hh, GETDATE(), GETUTCDATE()), DateTimeStamp) 
+3
source

Use the DATEADD function of SQL Server. You just have to know what not. time difference from your local time to UTC.

0
source

Source: https://habr.com/ru/post/1394478/


All Articles