--1.
CREATE FUNCTION IsLeapYear(@Year CHAR(4))
RETURNS BIT
AS
BEGIN
DECLARE @FirstDayInFeb DATETIME
DECLARE @LastDayInFeb DATETIME
DECLARE @ReturnValue BIT
SET @FirstDayInFeb = CONVERT(DATETIME, @Year+'-02-01')
SET @LastDayInFeb = DATEADD(M, 1, @FirstDayInFeb)
SET @LastDayInFeb = DATEADD(D, -1, @LastDayInFeb)
IF DATEPART(D, @LastDayInFeb) = 29
SET @ReturnValue = 1
ELSE
SET @ReturnValue = 0
RETURN @ReturnValue
END
GO
select dbo.IsLeapYear(1900)
--2.
CREATE FUNCTION IsLeapYear(@Year CHAR(4))
RETURNS BIT
AS
BEGIN
DECLARE @ReturnValue BIT
DECLARE @iYear INT
SET @iYear=CONVERT(INT,@Year)
IF (@iYear % 4 = 0 and @iYear % 100 != 0) or (@iYear % 400 = 0)
SET @ReturnValue = 1
ELSE
SET @ReturnValue = 0
RETURN @ReturnValue
END
GO
select dbo.IsLeapYear(2000)