The below SQL script will
help you to find, First & Last Date of the Current/Previous/Next
Quarter based on the current Date.
If you need to find Quarter and
previous quarter for any specific date, Then Replace GETDATE() with the date.
Hope This Helps!
--To get the first day of the previous quarter
SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) - 1, 0) As
Previous_Quarter_FirstDay
--To get the last day of the previous quarter:
SELECT DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0)) As Previous_Quarter_LastDay
--To get the first day of the current quarter:
SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0) As
Current_Quarter_FirstDay
--To get the last day of the current quarter:
SELECT DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +1, 0)) As
Current_Quarter_LastDay
--To get the first day of the next quarter:
SELECT DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) + 1, 0) As Next_Quarter_FirstDay
--To get the last day of the next quarter:
SELECT DATEADD (dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +2, 0)) As Next_Quarter_LastDay
No comments:
Post a Comment