Check Inputed Year is leap or not using SQL function

Below function is used to check wheather inputed year is leap year or not.

If inputed year is leap year then function will return "Y" otherwise return "N"



CREATE FUNCTION CheckLeapYear
(@Year Int)
RETURNS char
AS
BEGIN
DECLARE @LeapDate datetime
DECLARE @Day int

SET @LeapDate = CONVERT(VARCHAR(4), @Year) + '0228'
SET @Day = DATEPART(d, DATEADD(d, 1, @LeapDate))
IF (@Day = 29)
RETURN 'Y'
RETURN 'N'
END





e.g : 1. If i/p is
@Year =2008 then o/p 'Y'
2. If i/p is
@Year =2009 then o/p 'N'


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: