I\'d like to get the list of days between the two dates (including them) in a PostgreSQL database. For example, if I had:
This should do it:
select date '2012-06-29' + i
from generate_series(1, (select date '2012-07-3' - date '2012-06-29')) i
If you don't want to repeat the start_date in the subselect things get a bit more complicated:
with min_max (start_date, end_date) as (
values (date '2012-06-29', date '2012-07-3')
), date_range as (
select end_date - start_date as duration
from min_max
)
select start_date + i
from min_max
cross join generate_series(1, (select duration from date_range)) i;
(See maniek's answer for a much better version of the "no-repeat" problem)