Calculate Business Days

Simple, quick, not a lot of discussion, just the way I like it. 

Can anyone think of a quicker way?

declare @targetdate DATE
DECLARE @BusinessDays INT
DECLARE @dt DATE
 
SELECT 
    @targetdate = DATEADD(DAY,21,GETDATE())
 
 
 
--figure out how far out the targetdate is
--initialize
SELECT
        @BusinessDays = 0,
        @dt = GETDATE()
         
--loop through the time period between now and the target date
WHILE @dt < @targetdate BEGIN
    --potentially increment @BusinessDays
    SELECT @BusinessDays = @BusinessDays + IIF(DATEPART(WEEKDAY, @dt) IN (1, 7),0,1)
    --increment our date counter
    SELECT @dt = DATEADD(DAY,1,@dt)
end
 
 
PRINT @BusinessDays

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences