Question : Converting UTC time

Hi, All
I have a Sql Server table where historical data stored in UTC time. I need to do calculations on the data, but in Central time. Is there any T-sql function that will help me to adjust this timestamp to a Central time so I can correctly pick-up the data? (This is a backend development)

Please help ASAP
Thanks

Answer : Converting UTC time

You could simply use the DateAdd() functions, but you'll need to find out first what time zone you are in. You can do this by using the GetUTCDate() function.

Mind that this function uses whatever the server is configured like, so it might
a) be not correct (bad, bad admins !! =)
b) be correct on the server, but not correct for the data as the database was restored from another office in another time-zone

Anyway, have a go with this and I bet you'll be able to work forward from here :

-- see difference between utc & lcl
SELECT utc_time = GETUTCDATE(), lcl_time = GETDATE()

-- calculate difference between both
DECLARE @time_zone int
SELECT @time_zone = DateDiff(hour, GetUTCDate(), GetDate())

-- from utc to lcl
SELECT local_time = DateAdd(hour, @time_zone, '2005-12-15 15:07:28.000')

-- from lcl to utc
SELECT local_time = DateAdd(hour, - @time_zone, '2005-12-15 16:07:28.000')
Random Solutions  
 
programming4us programming4us