UTC Date Time Handling

Post date: Jun 25, 2011 7:21:11 PM

Great source code on the Code Project website for this.  Works well.  Contains all source material on the site and is free to become a member.  The project source is attached.


The general description of the project is:


SQL Server does not provide a simple way to convert a UTC datetime value to a local time value. This project includes a table (tbTimeZoneInfo) with data to provide the Time Zone information and two functions toconvert a UTC datetime value to any Local Time Zone.

The tbTimeZoneInfo table contains the Time Zone information for all the time zones from the registry underHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones. Anyone familiar with theTIME_ZONE_INFORMATION structure will recognize the structure of table tbTimeZoneInfo.

The function named GetLocalDateTime arguments are a TimeZoneID value from tbTimeZoneInfo and aUTC DateTime value. The GetUTCDate() function can be used to obtain the current UTC date.

Values in the tbTimeZoneInfo can be changed as needed. The values that are supplied in the form of SQLinsertion scripts may not be up to date. They were obtained from the registry at a point in time and may now be out of date.

Simply read the UTCToLocal_ReadMe.txt file for instructions on creating the objects, inserting data and testing the GetLocalDateTime function.