Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

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)

Get daylight savings time

By Langston Montgomery,

 

 

Hello everyone,

 

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.

Total article views: 1597 | Views in the last 30 days: 5
 
Related Articles
FORUM

Daylight Saving in SQL Server 200

Daylight saving

FORUM

Convert Unix Date Time to Julian - DST

Convert Unix datetime to Julian and accommodate daylight savings time

FORUM

How to convert an Access Last function to SQL Server

convert an Access Last function to SQL Server

SCRIPT

Function to convert UserAccountControl number to details text

Function that converts AD UserAccountControl number to details text

FORUM

convertion

convertion

Tags
daylight    
function    
savings    
script    
time    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones