I want to break this up into parts. First, let us assume that all your servers were located in Eastern time zone (observes daylight savings time). Then, you could do the following to find the Chicago local-time. This would work correctly for daylight savings time and standard time.declare @offsetFromChicago int;set @offsetFromChicago = 1;SELECT DATEADD(hour,DATEDIFF(hh,GETUTCDATE(),GETDATE())-1,GETUTCDATE()) as ChicagoTime;
Now part 2 - if your servers were located all over US and Canada, then you would need to indicate the offsetFromChicago for each location. So your function might be like this then:CREATE FUNCTION [dbo].[GetChicagoTime] ( @offsetFromChicago INT ) RETURNS DATETIMEasBEGIN return DATEADD(hour,DATEDIFF(hh,GETUTCDATE(),GETDATE())-@offsetFromChicago,GETUTCDATE());END
If you can't distinguish or program based on where the server is located, you will need some way of finding out the local time-zone information. You can get it from the OS using CLR procedures, if needed; there may be other ways. You would also need to take into account places like Arizona or Hawaii that do not observe daylight savings time.This of course, assumes that all time-zones are offset from UTC by full hours and not by fractional hours. If your servers are in places that are 5.5 hours ahead of GMT for example, you would need to use minutes rather than hours in your calculations.