January 9, 2013 at 2:44 am
Hi,
I am using Sql server 2008,
My requirement is to find the first date of the previous Quater of the given date.
Example,
Givendate Quater Required Output
2013-01-20 1 2012-10-01
2013-03-20 1 2012-10-01
2013-04-10 2 2013-01-01
2012-10-10 4 2012-07-01
Please Help me,
As I need this very urgently.
Thanks in Advance!
January 9, 2013 at 2:53 am
I would say this is where a calendar table like this one will come into best fit. http://www.sqlservercentral.com/scripts/Date/68389/
Then you can query it to find todays quarter, then lookup the previous quarters first day.
January 9, 2013 at 3:54 am
I agree with Anthony... a calendar table is probably a better idea, but this should get you the first day of the previous quarter.
declare @d datetime
set @d = getdate() -- or whatever date you want to test
select DATEADD(quarter,DATEDIFF(quarter,0,@d)-1,0)
January 9, 2013 at 4:07 am
Thanks Friends!
It works for me.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply