Determine whether Year is a Leap Year or Not using Function

Rajesh_Kumar
Posted by Rajesh_Kumar under Sql Server category on | Points: 40 | Views : 1117
create function fn_check_LeapYear(@year int)
returns bit
as
begin
return(select case datepart(mm,dateadd(dd, 1, cast((cast(@year as varchar(4)) + '0228') as datetime)))
when 2 then 1
else 0
end)
end
go


Select fn_check_LeapYear(2014) as 'IsLeapYear'

Comments or Responses

Login to post response