One of the app is inserting date in UTC format (column CreateDate). When reporting from this table, I used a difference in hours between the inbuilt GetUTCDate() and GetDate() and added the same to the CreateDate column. I was hoping to not worry about the daylight time. Is this approach OK?

SELECT GetDate()
DECLARE @DifferenceInHoursBetween INT
SELECT @DifferenceInHoursBetween = DATEDIFF(HH,GetUTCDate(), GETDATE())
SELECT  USER_ID, CreateDate AS [DateTime IN UTC], DATEADD(HOUR,@DifferenceInHoursBetween,CreateDate) AS [LocalDateTime] FROM EVENTLOG(nolock)


SELECT GetUTCDate() AS [UTCDateTime]
SELECT GetDate() AS [LocalDateTime]
DECLARE @DifferenceInHoursBetween INT
SELECT @DifferenceInHoursBetween = DATEDIFF(HH,GetUTCDate(), GETDATE())
SELECT @DifferenceInHoursBetween AS [Difference in Hours]

-- UTCDateTime

2019-01-22 16:34:46.943


2019-01-22 08:34:46.943

-- Difference in hours -8

  • 1
    \$\begingroup\$ good approach is to save the date in UTC \$\endgroup\$ Commented Jan 23, 2019 at 13:32
  • \$\begingroup\$ To be fair, if DST was your initial concern, your SQL is not working as intended. \$\endgroup\$
    – dfhwze
    Commented Jul 27, 2019 at 18:20

1 Answer 1



You don't need to calculate the difference from two temporary values GetUTCDate and GETDATE.

SELECT @DifferenceInHoursBetween = DATEDIFF(HH,GetUTCDate(), GETDATE())

Proposed Solution

Instead, you could apply the local time zone offset to the specified datetime.

    CreateDate AS [DateTime IN UTC], 
        SWITCHOFFSET(CONVERT(datetimeoffset, CreateDate), 
            DATENAME(TzOffset, SYSDATETIMEOFFSET()))) AS [LocalDateTime] 

Fiddle: SQL Server 2017

enter image description here

Daylight Savings Time

Both methods, OP and solution don't take into account DST. And unfortunately, SQL Server does not come with a built-in conversion from DST. You'd have to make a function yourself. More about DST in SQL Server


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.