How to Find Leap Year in sql server 2012
How to determine whether a year is a leap year
To determine whether a year is a leap year, follow these steps:- If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
- If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
- If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
- The year is a leap year (it has 366 days).
- The year is not a leap year (it has 365 days).
Here is the code for Finding LEAP YEAR in SQL SERVER
declare @chkyear int = 2011;
if @chkyear % 4 = 0
begin
if @chkyear % 100 =0
begin
if @chkyear % 400 = 0
Print CAST(@chkyear as varchar(4)) + N' is a Leap year';
end
else Print CAST(@chkyear as varchar(4)) + N' is a Leap year';
end
else print CAST(@chkyear as varchar(4)) + N' is not a Leap year';
Tags:Determine leap year , check for Leap year,Detecting a Leap Year in sql server 2012,Function to determine a leap year.