Search This Blog

Monday, January 23, 2012

Find the leap year using UDF function in SQL server 2005/2008

This function will return , the passed year is a leap year or not


CREATE FUNCTION dbo.fn_IsLeapYear (@year int)
RETURNS BIT
as
BEGIN
    RETURN(SELECT CASE DATEPART(MM, DATEADD(DD, 1, CAST((CAST(@YEAR AS VARCHAR(4)) + '0228') AS DATETIME)))
    WHEN 2 THEN 1
    ELSE 0
    END)
END
GO
Ref:http://ashiskrdas.blogspot.com/

No comments :

Post a Comment