To find out Leap year is use to be a small assignment. Its a very popular question and I’m sure we all have done it from different different programming languages. We all have used some predefined functions to solve this. Today we will see how to write a User Defined Function for checking Leap Year but from MS SQL Server.

CREATE FUNCTION [dbo].[fn_CheckLeapYear] ( @InputDate DATETIME )
RETURNS BIT
AS
BEGIN

IF ( YEAR(@InputDate) % 4 = 0
AND YEAR(@InputDate) % 100 != 0
)
OR YEAR(@InputDate) % 400 = 0
RETURN 1

RETURN 0

END

Note : Above function will return bit value.