Re: Given 02-01-2006 to 02-28-2006, output all days. - Mailing list pgsql-sql

From Owen Jacobson
Subject Re: Given 02-01-2006 to 02-28-2006, output all days.
Date
Msg-id 144D12D7DD4EC04F99241498BB4EEDCC220D19@nelson.osl.com
Whole thread Raw
In response to Given 02-01-2006 to 02-28-2006, output all days.  (Henry Ortega <juandelacruz@gmail.com>)
Responses Re: Given 02-01-2006 to 02-28-2006, output all days.  ("Pedro B." <pedro.borracha@netcabo.pt>)
List 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-012006-02-022006-02-032006-02-042006-02-052006-02-062006-02-07
(7 rows)



pgsql-sql by date:

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