How to get first and last day of previous month in SQL Server?

SQL Tutorial

How to get first and last day of previous month in SQL Server?

If you wants to get first and last day of previous month in SQL Server, then you need to follow the below query to get your desired output.

To get the first day of previous month, execute the below sql query:

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

To get the last day of previous month, execute the below sql query:

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

 

Hope this will help you a lot.

 

Nahidur Rahman Rifath

Passionate Software Engineer, Content Writer, Reader

Leave a Reply

Your email address will not be published. Required fields are marked *