0

I want to display all the dates that are included in a particular quarter ex: if my input is Q1 and 2021, my output should be

01/01/2021
01/02/2021
--------
---------
-------
03/31/2021
Dale K
  • 25,246
  • 15
  • 42
  • 71
sandeep.mishra
  • 825
  • 4
  • 19
  • 40
  • You probably would need to use some sort of a date dimension that tracks which dates are in each quarter. This is something typically used in Data Warehousing, allowing analysts to select dates in either "natural" quarters, or financial quarters (and months, weeks, years, etc.). Google Calendar Dimension and you'll most likely will find a ton of scripts to generate one for you. – SchmitzIT May 21 '21 at 06:41
  • Here is a question about getting all the days in a month, maybe it would be possible to alter so that it works to get the days in the three months that are in a quarter: https://stackoverflow.com/questions/37027684/get-all-dates-of-given-month-and-year-in-sql-server – mortb May 21 '21 at 06:42
  • Note that financial quarters vary around the globe. – Jon P May 21 '21 at 06:47

1 Answers1

0

I guess you can start from something like this^

DECLARE @InFirstQuarterDate DATE='20210101';
DECLARE @InLAstQuarterDate DATE=DATEADD(DAY,-1, DATEADD(MONTH,3*DATEPART(QUARTER,@InFirstQuarterDate), DATENAME(YEAR,@InFirstQuarterDate)));

 --SELECT @InFirstQuarterDate,@InLAstQuarterDate

WITH CTE AS
(
  SELECT @InFirstQuarterDate AS DD
     UNION ALL
  SELECT DATEADD(DAY,1,C.DD)AS DD
    FROM CTE AS C
     WHERE DATEADD(DAY,1,C.DD)<=@InLAstQuarterDate
)
SELECT C.DD
 FROM CTE AS C
Sergey
  • 4,719
  • 1
  • 6
  • 11