Here's a simple way to find the Find First and Last Day of the current quarter in SQL Server 2005/2008
SELECT DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0) as FirstDayOfQuarter
SELECT DATEADD(qq,DATEDIFF(qq,-1,GETDATE()),-1) as LastDayOfQuarter
OUTPUT
FirstDayOfQuarter LastDayOfQuarter
2009-04-01 00:00:00.000 2009-06-30 00:00:00.000
Thanks a lot for your gem :)
ReplyDeleteThank you very much, also it works for first day of the month, quarter and year.
ReplyDeleteIt's really a gem.
Thats great - any ideas how to do this in the code of ssrs i.e. in c#?
ReplyDeleteThanks :)
Thanks..its working..
ReplyDeleteBut i didn't get d logic..
If possible plz Mention d logic
......MAster ANil
This comment has been removed by the author.
ReplyDeleteThank you very much. Is there a easy way to get the first day and the last day of the previous quarter?
ReplyDeleteTo get the First Day and Last Day of 'Last' quarter, try this query
ReplyDeleteSELECT DATEADD(qq,DATEDIFF(qq,0,GETDATE())-1,0) as FirstDayOfLastQuarter
SELECT DATEADD(qq,DATEDIFF(qq,0,GETDATE()),-1) as LastDayOfLastQuarter
beautiful code!
ReplyDeleteI needed first and last days of *last* quarter for my requirements, so I did:
SELECT DATEADD(qq,-1,DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0))
SELECT DATEADD(qq,-1,DATEADD(qq,DATEDIFF(qq,-1,GETDATE()),-1))
oops--sorry--didn't see your last comment where you already did the first and last day of last quarter!
ReplyDelete