Hey Rob ...
Thanks for correcting that mistake of mine ....
Apologies for not testing my code to the extent that I should have done .....
Please take a look at your First and Last Day of a Quarter example.
ARTICLE: http://www.sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk
DECLARE @Date datetime SET @Date = '10/21/04'
--First Day of the Quarter
SELECT DATEADD(qq, DATEPART(qq, @Date), DATEADD(dd, -(DATEPART(dy, @Date) - 1), @Date)) [First Day of the Quarter - INCORRECT],
DATEADD(qq, DATEPART(qq, @Date) - 1, DATEADD(dd, -(DATEPART(dy, @Date) - 1), @Date)) [First Day of the Quarter - CORRECTED]
PRINT ''
--Last Day of the Quarter
SELECT DATEADD(qq, DATEPART(qq, @Date) + 1, DATEADD(dd, -(DATEPART(dy, @Date)), @Date)) [Last Day of the Quarter - INCORRECT],
DATEADD(qq, DATEPART(qq, @Date), DATEADD(dd, -(DATEPART(dy, @Date) + 0), @Date)) [Last Day of the Quarter - CORRECTED]
PRINT ''
Excellent article; keep up the good work.
Rob
PS : Not unit tested this code too ... didn't get the time .... hope this does not screw up in some other case ... apologies again !!!!