Calculate the last day of the prior quarter

Get the current date

SELECT CONVERT(DATE,GETDATE()) [Current Date]

Get the 1st date of the quarter for the current date

SELECT CONVERT(DATE, DATEADD(QQ, DATEDIFF(QQ, 0, GETDATE())  ,0)) [Current Quarter 1st Date]

Get the last date of the quarter for the current date

SELECT CONVERT(DATE,DATEADD(d, -1, DATEADD(q, DATEDIFF(q, 0, GETDATE()) +1, 0))) [Current Quarter Last Date]

Get the 1st date of the next quarter for the current date

SELECT CONVERT(DATE, DATEADD(QQ, DATEDIFF(QQ, 0, GETDATE()) +1 ,0)) [Next Quarter 1st Date]

Get the last date of the next quarter for the current date

SELECT CONVERT(DATE,DATEADD(d, -1, DATEADD(q, DATEDIFF(q, 0, GETDATE()) +2, 0))) [Next Quarter Last Date]

I came up with this (tested for all months):

select dateadd(dd,-1,dateadd(qq,datediff(qq,0,'11/19/2008'),0)),
       dateadd(dd,-1,dateadd(qq,datediff(qq,0,'10/19/2008'),0)),
       dateadd(dd,-1,dateadd(qq,datediff(qq,0,'12/19/2008'),0))

It might turn out to be the simplest.


If @Date has the date in question

Select DateAdd(day, -1, dateadd(qq, DateDiff(qq, 0, @Date), 0)) 

EDIT: Thanks to @strEagle below, simpler still is:

Select dateadd(qq, DateDiff(qq, 0, @Date), -1) 

Actually simpler is:

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