Search This Blog

WeeksInAMonth

CREATE FUNCTION dbo.WeeksInAMonth(@Date DATETIME)
RETURNS INT
AS
BEGIN
RETURN DATEPART(week, @Date) - DATEPART(week, CONVERT(CHAR(6), @Date, 112)+'01') + 1
END
GO

SELECT dbo.WeeksInAMonth ('19980228')

No comments: