DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Get The First And Last Day Of The Previous Month T-SQL

03.10.2006
| 633 views |
  • submit to reddit
        // Get the first and last day of the previous month T-SQL

declare @date datetime
set @date = dateadd(m,-1,getdate())

--get first day of month 
select dateadd(m, datediff(m, 0, @date), 0)

--get last day of month 
select dateadd(m, datediff(m, 0, dateadd(m, 1, @date)), -1)