Function to Find Leap Year Using EOMONTH Function in SQL Server

Hello to everyone,

In this article I will talk about how to find leap years in SQL Server.

You can read my previous article on the subject at the link below.

  Function to Find Leap Year in SQL Server

According to the comment made by Barak G. on the Linkedin platform, I revised the leap year check function.

You can easily do this with the help of the function below.

SELECT dbo.FindLeapYearEOMONTH('2021.01.01') AS ResultCREATE FUNCTION FindLeapYearEOMONTH
    @Date DATE
    DECLARE @Result VARCHAR(30);
    IF DAY(EOMONTH(@Date, 2 - MONTH(@Date))) = 29
        SET @Result = 'The year is leap year';
        SET @Result = 'The year is not leap year';
	RETURN @Result

--Use of Function

SELECT dbo.FindLeapYearEOMONTH('2021.01.01') AS Result

When you run the code you will get the following result.

Function to Find Leap Year Using EOMONTH Function in SQL Server

As you can see, the leap year is calculated.

Good luck to everyone in business and life.


Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!