Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By Langston Montgomery,
Many of us have come across cases where we need to convert a time (such as UTC) to local time, but what about those parts of the world where daylight savings time is observed?
This function will return the daylight savings date/time for a given year in accordance with historical records: http://www.energy.ca.gov/daylightsaving.html#chart
This way, no lookup tables are needed. All you have to know is what timezone you are converting from and to, because as long as you have the date when daylight savings begins/ends, then it should be fairly easy to write some case logic to convert the date. This script also contains an example of this function's use by converting UTC to PST.
Caveat: The function can return undesirable results if the SET DATEFIRST statement is set to anything other than Sunday.
Credits: Much credit to those out there who provided much of the crucial code that went into building this function.
Convert () function in SQL Server to convert an expression from one data type to another data type
Convert Unix datetime to Julian and accommodate daylight savings time
convert an Access Last function to SQL Server
Function that converts AD UserAccountControl number to details text