Simple function to check, if year is a leap year or not.
/*********************************************** Leap year function. It checks, if any given year is a leap year or not. ------------------- Example: select dbo.IsLeapYear(2013) - should return 0 select dbo.IsLeapYear(2016) - should return 1 ***********************************************/ CREATE FUNCTION [dbo].[IsLeapYear] ( @Year INT ) RETURNS BIT AS BEGIN DECLARE @Date DATETIME ,@YearString VARCHAR(4) SET @YearString = CAST(@Year AS VARCHAR) /* calculate March 1st */ SET @Date = CONVERT(DATETIME, '03/01/' + @YearString, 101) /* calculate the date of last day in Fabruary */ SET @Date = DATEADD(d, -1, @Date) IF ( DAY(@Date) = 29 ) RETURN 1 RETURN 0 END