SQL Clone
SQLServerCentral is supported by Redgate
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: 2863 | Views in the last 30 days: 7
Related Articles

Compute Holiday Day of the Month for any Year

This script provides the day of the month for the standard bank holidays for any given year. This i...


TSQL copy data in weekdays

TSQL copy data in weekdays


Adding workdays

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


The Bones of SQL - The Holiday Table

This second part to a previous article on Calendar table generation shows how to create a holiday ta...