I need to generate a list of dates between two dates start date and end date here I need from 1/1/2022 to the end of the year on AWS Athena without creating table I need only query view the output should be:
|date|
|--|
|1/1/2022 |
|2/1/2022 |
|3/1/2022 |
etc to a specific date.
CodePudding user response:
You can use the sequence function to generate an array with a start date and an end date
CodePudding user response:
You can use sequence
function which supports dates and timestamps:
sequence(
current_date, -- some start date
current_date interval '3' day, -- some end date
interval '1' day) -- step
And then use unnest
which will flatten the generated array:
select t.date
from (select sequence(current_date, current_date interval '3' day, interval '1' day) dates),
unnest(dates) as t(date);
Output:
date |
---|
2022-09-26 |
2022-09-27 |
2022-09-28 |
2022-09-29 |