Home Forums SQL Server 7,2000 T-SQL Date Calculation Excluding Weekend & Holiday RE: Date Calculation Excluding Weekend & Holiday

  • To exclude weekends, there is a 'simple' solution doing some simple 'date'math. This has been solved before on these forums...

    To also exclude holidays is a lot trickier. The only 'easy' solution I can see is to build a table that holds all dates that should be excluded.

    The statement would be something like

    
    
    CREATE TABLE NonBusinessDays
    (NBDDate smalldatetime)
    GO

    SELECT datediff(day, @creation_date, getdate()) - count(*) AS Outstanding
    FROM NonBusinessDays
    WHERE NBDDate >= @creation_date and NBDDate < getdate()

    Either join to your source table or pass in Creation_date as a parameter.