Last active
August 29, 2015 14:10
-
-
Save sbealer/f876cffdc2b50f976258 to your computer and use it in GitHub Desktop.
SQL Server - Get local datetime from utc datetime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- the utc value | |
declare @utc datetime = '20/11/2014 05:14' | |
-- the local time | |
select DATEADD(hh, DATEDIFF(hh, getutcdate(), getdate()), @utc) | |
--Conversely (to go from local to UTC) | |
DECLARE @LOCAL DATETIME = getdate(); | |
SELECT | |
DATEADD(HH, DATEDIFF(HH, GETDATE(), GETUTCDATE()), @LOCAL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment