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.
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.