How to Find Last Date of Month in SQL Server [ EOMONTH ]

SQL Server gets the last date of the month: Here in this article, we learn how to get the end date of any given month. Let assume one has the requirement to find start date and end date of the current month in SQL Server. In short, we need to get First Day of the current month or previous month, or Last day ( end date) of the current month or any given month in SQL server.

If you are using SQL server 2012 or above, then there is a built-in method EOMONTH which display the last date on the specified date.

What is an EOMONTH function?

The EOMONTH function returns the last date of the month that contains the specified date, with an optional offset. In short with this function you can get the last day of given date or current date. This function supports in SQL Server 2012 or higher version. I.e., it will not work in SQL Server 2008, SQL Server 2005.

Syntax : = EOMONTH(start_date, months)

EOMONTH takes 2 parameters, first as StartDate and next as month travels from that start date, and then outputs the last day of that month.

If we set parameter months as 0, then EOMONTH will output the last day of the month in which StartDate falls.

Query to find the Month End Date in SQL Server

1) To find the last date of the current month using EOMONTH

Here we set month as 0 which gives the current month Last Date in SQL Server

Conclusion: Byusing EOMONTH in SQL Server 2012 or above we can get month start date and end date. As here we learned how to show Current Month end date, Next Month end date or Previous month end date. We also did same for SQL server lower version .i.e (SQL SEVRVER 2005 / SQL SERVER 2008).

Hope you like this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!