Lynn Pettis (6/2/2016)
The following should help:
d e c la r e -- spaced to post from work
@ThisDate date = getdate();
select
@ThisDate,
dateadd(quarter,datediff(quarter,0,@ThisDate),0) CurrentQuarterStart,
dateadd(quarter,datediff(quarter,0,@ThisDate) - 1,0) PreviousQuarterStart,
dateadd(quarter,datediff(quarter,0,@ThisDate),-1) PreviousQuarterEnd;
Personally, I would use >= PreviousQuarterStart and < CurrentQuarterStart for a filter in a WHERE clause.
+1 for the simplicity and + 1,000,000 for the WHERE clause example to avoid accidental inclusion of whole dates for the next quarter.
--Jeff Moden
Change is inevitable... Change for the better is not.