conversion of Local date time to Universal time

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 289
DECLARE @LocalDate DATETIME
SET @LocalDate = GETDATE()

-- convert local date to utc date
DECLARE @UTCDate DATETIME
SET @UTCDate = DATEADD(Hour, DATEDIFF(Hour, GETUTCDATE(), GETDATE()), @LocalDate)

-- convert utc date to local date
DECLARE @LocalDate2 DATETIME
SET @LocalDate2 = DATEADD(Hour, DATEDIFF(Hour, GETDATE(), GETUTCDATE()), @UTCDate)

SELECT @LocalDate GivenDate, @UTCDate Universal, @LocalDate2 LocalFromUniversalDate


OUTPUT:
GivenDate Universal LocalFromUniversalDate
2014-07-24 11:23:01.190 2014-07-24 17:23:01.190 2014-07-24 11:23:01.190

Comments or Responses

Login to post response