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)

Number of Weekdays between two dates - Set Based

By Calvin Lawson,

Inspired by a post here at SQLServerCentral, I wrote this function to calculate the number of days between two dates that are weekdays. In order to achieve this I used a common SQL table that contains a sequence of number for 1 to X. This was used as an input to the datediff function, and the resulting date's "weekday" is checked to see if it was Saturday or Sunday (1 or 7). If so 0 otherwise 1, which is then summed up.

Total article views: 282 | Views in the last 30 days: 1