Skip to content

Instantly share code, notes, and snippets.

@sbealer
Last active August 29, 2015 14:10
Show Gist options
  • Save sbealer/f876cffdc2b50f976258 to your computer and use it in GitHub Desktop.
Save sbealer/f876cffdc2b50f976258 to your computer and use it in GitHub Desktop.
SQL Server - Get local datetime from utc datetime
-- 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