This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output for counting the total number of working days between given Two Dates.
Input Dates:
1 2 |
SET @StartDate = '2018-01-01' SET @EndDate = '2018-01-31' |
Required Output:
1 2 3 |
TotalWorkingDays ---------------- 23 |
Solution:
1 2 3 4 5 6 7 8 9 10 |
DECLARE @StartDate DATETIME DECLARE @EndDate DATETIME SET @StartDate = '2018-01-01' SET @EndDate = '2018-01-31' SELECT (DATEDIFF(dd, @StartDate, @EndDate) + 1) -(DATEDIFF(wk, @StartDate, @EndDate) * 2) -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END) -(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END) AS TotalWorkingDays |
Please try the different solution for this puzzle and share it via comment...