Re: Given 02-01-2006 to 02-28-2006, output all days.

From: "Owen Jacobson" <ojacobson(at)osl(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Given 02-01-2006 to 02-28-2006, output all days.
Date: 2006-02-17 21:14:46
Message-ID: 144D12D7DD4EC04F99241498BB4EEDCC220D19@nelson.osl.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Henry Ortega wrote:

(question about set of all days between two dates)

I don't know of a builtin way to do it off the top of my head, but it's a pretty simple function to write:

create function days (start date, finish date) returns setof date as $$
declare
curdate date;
begin
curdate := start;
while (curdate <= finish) loop
return next curdate;
curdate := curdate + 1;
end loop;
return;
end;
$$ language plpgsql;

# select * from days ('2006-02-01', '2006-02-07');
days
------------
2006-02-01
2006-02-02
2006-02-03
2006-02-04
2006-02-05
2006-02-06
2006-02-07
(7 rows)

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2006-02-17 21:20:02 Re: Given 02-01-2006 to 02-28-2006, output all days.
Previous Message Henry Ortega 2006-02-17 21:07:28 Given 02-01-2006 to 02-28-2006, output all days.