Here is an example query that illustrates how to use the function to easily convert to and from UTC/GMT time and the SQL Server's local time.
SELECT GETDATE() AS 'Local Time',
GETUTCDATE() AS 'GMT Time',
DATEADD(HOUR, dbo.UDF_GetGMTOffset(), GETUTCDATE()) AS 'GMT Time to Local Time',
DATEADD(HOUR, dbo.UDF_GetGMTOffset() * -1, GETDATE()) AS 'Local Time to GMT Time',
dbo.UDF_GetGMTOffset() AS 'GMT Offset'
Local Time | GMT Time | GMT Time to Local Time | Local Time to GMT Time | GMT Offset |
---|---|---|---|---|
2010-11-04 09:45:55.827 | 2010-11-04 14:45:55.827 | 2010-11-04 09:45:55.827 | 2010-11-04 14:45:55.827 | -5 |