
CREATE FUNCTION dbo.GetWeekStartSaturday
(
    @InputDate DATETIME
)
RETURNS Date
AS
BEGIN
	DECLARE @RESULT as DATETIME
    --SELECT @RESULT=DATEADD(DAY,-((DATEPART(WEEKDAY, @InputDate) + @@DATEFIRST - 7) % 7), @InputDate)
    SELECT @RESULT=DATEADD(DAY,-((DATEDIFF(DAY, '19000106', @InputDate) % 7)),@InputDate)
	RETURN @RESULT
END
GO

