CREATE FUNCTION [dbo].[GetDatesInBetween](@FromDate DATETIME, @ToDate DATETIME, @IncludeWeekends BIT ) RETURNS @DateTable TABLE(DATE DATETIME) AS BEGIN INSERT INTO @DateTable (DATE) VALUES (@FromDate) WHILE @FromDate < @ToDate BEGIN SELECT @FromDate = DATEADD(D, 1, @FromDate) IF @IncludeWeekends = 1 INSERT INTO @DateTable (DATE) VALUES (@FromDate) ELSE IF DATENAME(dw, @FromDate) <> 'Thursday' AND DATENAME(dw, @FromDate) <> 'Friday' INSERT INTO @DateTable (DATE) VALUES (@FromDate) END RETURN END
I'll write what I think, I'll share what I like. If you do not like, I'm Sorry