Finding First and Last Day of Month with EOMONTH Function in SQL Server

Hello everyone,

In this article, I will give information about finding the first and last day of the month with the EOMONTH function in SQL Server.

In SQL Server you may need the first and last days of a month in some cases.

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

--Find the first day of the month

DECLARE @Date1 DATETIME;
SET @Date1 = GETDATE();
SELECT DATEADD(DAY, 1, EOMONTH(@Date1, -1)) Firstdayofthemonth

--Find the last day of the month

DECLARE @Date2 DATETIME;
SET @Date2 = GETDATE();
SELECT EOMONTH(@Date2) Lastdayofthemonth;

 

When you run the code, you will get a result like the one below.

Finding First and Last Day of Month with EOMONTH Function in SQL Server

As you can see, the information for the first and last day of the month has arrived.

Good luck to everyone in business and life.

180 Views

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!