How to Get First and Last Day of a Month in SQL Server

To get the first day of the previous month in SQL Server, use the following code:

SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) - 1, 0)

first_day_of_last_month

To get the last day of the previous month:

SELECT DATEADD(DAY, -(DAY(GETDATE())), GETDATE())

last_day_of_last_month

To get the first day of the current month:

SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)

first_day_of_current_month

To get the last day of the current month:

SELECT DATEADD (dd, -1, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) + 1, 0))

last_day_of_current_month

To get the first day of the next month:

SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) + 1, 0)

first_day_of_next_month

To get the last day of the next month:

SELECT DATEADD (dd, -1, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) + 2, 0))

last_day_of_next_month

In SQL Server 2012 and later you can use EOMONTH Function to Get First and Last Day of a Month in SQL Server:
EOMONTH Function to Get First and Last Day of a Month in SQL Server

Related blog post:
Code to get the last day of the month in SQL Server