Posted by & filed under Development.

I needed to offset the current time in MS SQL 2005 for a quick fix. I wanted to make sure the solution would not have to be maintained when daylight savings time changed. Taking the difference between the GETUTCDATE() and GETDATE() functions will generate the server’s current time zone offset from UTC time.

DECLARE @timezoneOffset INT
SELECT @timezoneOffset = (DATEDIFF(hh,GETDATE(),GETUTCDATE())) * -1;
SELECT DATEADD(hh, @timezoneOffset, GETUTCDATE()), GETDATE()

Trackbacks/Pingbacks

  1.  Tweets that mention aaronkjackson.com » Offsetting the time zone in MS SQL 2005 -- Topsy.com

Leave a Reply

  • (will not be published)