How to get first & last day of the previous month

The below-given script may help you.

This query will return the first day of the previous month
SELECT CONVERT(DATE,DATEADD(MM, DATEDIFF(MM, 0, GETDATE())-1, 0))

This query will return last day of the previous month
SELECT CONVERT(DATE,DATEADD(MS, -3, DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) , 0)))

To get the first and last day of the current month use following query
SELECT CONVERT(DATE,DATEADD(MM, DATEDIFF(MM, 0, GETDATE()), 0)) AS FirstDay

SELECT CONVERT(DATE,DATEADD(MS, -3, DATEADD(MM, DATEDIFF(MM, 0, GETDATE())+1 , 0))) AS LastDay

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...