Number of Working days excluding weekend

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 317
--No. of Working days excluding Weekend
DECLARE @start datetime2 = '2014-08-27'
DECLARE @end datetime2 = '2014-09-09'
SELECT
(DATEDIFF(dd, @Start, @End) + 1) -(DATEDIFF(wk, @Start, @End) * 2)
-(CASE WHEN DATENAME(dw, @Start) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @End) = 'Saturday' THEN 1 ELSE 0 END)

Comments or Responses

Login to post response