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)

Calculate U.S. Holidays

By Boyd Tyrrell,

You will need to use the Date Calendar script created by Sean Smith on the SQL Server Central website here http://www.sqlservercentral.com/scripts/Date/68389/ This is a great tool Sean wrote, if you have not seen it!

Then modify it to add a column is_workday. Just add a column in the CREATE TABLE section after is_weekday, add an is_workday column. Then scroll down to the UPDATE for is_weekday and copy that code and paste new renaming it is_workday. Run Sean's script and you will now have an is_workday column populated with the same values as is_weekday.

Once you have your Date Calendar table, you can run this Calculate Holidays script (U.S. holidays only) to flag the is_workday column for holidays. You will need to remark or modify holidays based on your business rules.

We use this to schedule business due dates for tasks of length n, so our deliverables timelines skip weekends and holidays.

 

Total article views: 2601 | Views in the last 30 days: 15
 
Related Articles
FORUM

TSQL copy data in weekdays

TSQL copy data in weekdays

FORUM

Adding workdays

Sergiy, this goes with my last trigger post, but this is kind of a new topic. I made a test table f...

FORUM

count of non-holiday weekdays

Hi Expert, I want to populate records in my one of the column as per below, count of non...

SCRIPT

Create bank holidays table

Do you know what happens if a holiday falls on a weekend? This script will help you.

Tags
calendar    
date    
holiday    
 
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