how to find end of quarter given a date in the quarter

Posted by Ramy on Stack Overflow See other posts from Stack Overflow or by Ramy
Published on 2011-01-06T23:10:33Z Indexed on 2011/01/06 23:53 UTC
Read the original article Hit count: 185

Filed under:
|

If i'm given a date (say @d = '11-25-2010'), how can I determine the end of the quarter from that date. I'd like to use a timestamp one second before midnight.

I can get this:

select dateadd(qq, datediff(qq, 0, getdate()), 0) as quarterStart

which gives me: '10-1-2010'

and I use this for one second before midnight of a given day:

select DateAdd(second, -1, DateAdd(day, DateDiff(day, 0, @d))+1, 0) ) AS DayEnd

in the end, a quarterEnd method would give me '12-31-2010 23:59:00'

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql-server-2008