0 Replies - 1354 Views - Last Post: 28 July 2008 - 03:12 AM

#1 dineeshd   User is offline

  • member icon

Reputation: 39
  • View blog
  • Posts: 619
  • Joined: 30-June 08

MSSQL Snippet to find out the Leap Year

Posted 28 July 2008 - 03:12 AM

Description: Usage : SELECT dbo.udf_LeapYearCheck(2008)This snippet will return '1' if the given year is leap year, else '0'.
IF EXISTS (SELECT NAME FROM sysobjects WHERE NAME = 'udf_LeapYearCheck' AND type = 'FN')
	DROP FUNCTION udf_LeapYearCheck
GO
CREATE FUNCTION dbo.udf_LeapYearCheck (@in_Year INT)
	RETURNS INT
AS
BEGIN
    RETURN(
    	SELECT CASE (DATEPART(MM, DATEADD(DD, 1, CAST((CAST(@in_Year AS VARCHAR(4)) + '0228') AS DATETIME)))) 
	WHEN 2 THEN 1 ELSE 0 END
    )
END
GO


Is This A Good Question/Topic? 0
  • +

Page 1 of 1