CREATE FUNCTION fnc_NumberOfWeekEnds(@dFrom
DATETIME,
@dTo DATETIME)
Declare
@weekends int
While @dFrom
<= @dTo Begin
If ((datepart(dw, @dFrom) = 1) OR (datepart(dw, @dFrom) = 7))
Set @weekends = @weekends + 1
Set @dFrom = DateAdd(d, 1, @dFrom)
SELECT fnc_NumberOfWeekEnds('2/27/2013','3/10/2013')
Reference with other date parts