The DATEDIFF function allows to find out the dates difference between the two dates. I am just wondering if there is any easy way to find the dates difference excluding weekends?
I have created next code:
SET @start = CONVERT(datetime, '23.11.2011', 104)
SET @finish = CONVERT(datetime, '29.11.2011', 104)
SET @result = 0
WHILE @start < @finish
BEGIN
IF (DATEPART(dw, @start) <> 7) AND (DATEPART(dw, @start) <> 1)
BEGIN
SET @result = @result + 1
END
SET @start = DATEADD(dd, 1, @start)
END
PRINT @result
But I am looking for the better solution.