SQL

ALTER FUNCTION [dbo].[WeekdaysInInterval] ( @StartDate SMALLDATETIME, @EndDate SMALLDATETIME, @day_of_week VARCHAR(9) ) RETURNS INT AS BEGIN DECLARE @found BIT, @num INT SET @found = 0 --find first occurence of day of week in interval WHILE @found = 0 AND (@StartDate < @EndDate) BEGIN IF DATENAME(weekday,@StartDate) = @day_of_week BEGIN SET @found = 1 END ELSE SET @StartDate = DATEADD(day,1,@StartDate) END --find number of weeks with this day of week included SET @num = (DATEDIFF(day,@StartDate, @EndDate) / 7) + 1 RETURN @num END

and use as

SQL

select dbo.WeekdaysInInterval('02/05/2012','02/25/2012','saturday');