Calculating Number of Working Days between two dates

Kirthiga
Posted by Kirthiga under Sql Server category on | Points: 40 | Views : 1414
Declare @StartDay datetime, @EndDay datetime
Set @StartDay='2013-01-01'
Set @EndDay='2013-05-31'

;with cte(Date) as
(
select @StartDay
union all
select Date+1 from cte where Date < @EndDay
)
select DATENAME(M,Date)Months,count(Date)[No Of Working Days] from cte
where DATENAME(W,Date) not in ('sunday','saturday')
group by DATENAME(M,Date) option (MAXRECURSION 400)

Comments or Responses

Login to post response