SET DATEFIRST 7
declare @start as date
declare @end as date
set @start = '17/12/2013'
set @end = '17/01/2014'
declare @start_hr as time
declare @end_hr as time
set @start_hr = '9:00'
set @end_hr = '17:00'
declare @workdayscount as int
set @workdayscount = 0
while @start < @end
begin
set @workdayscount = @workdayscount + case when datepart(weekday, @start) in (1, 2, 3, 4, 5) then 1 else 0 end
set @start = dateadd(day, 1, @start)
end
select @workdayscount
select @workdayscount * datediff(hour, @start_hr, @end_hr)
1. SET DATEFIRST 7 - sets the first weekday to Saunday.
2. The list (1, 2, 3, 4, 5) represents the working days - form Sunday to Thursday