pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Owen Jacobson <ojacobson@osl.com>
To: pgsql-sql@postgresql.org
Subject: Re: Given 02-01-2006 to 02-28-2006, output all days.
Date: Fri, 17 Feb 2006 13:14:46 -0800
Message-ID: <144D12D7DD4EC04F99241498BB4EEDCC220D19@nelson.osl.com> (raw)

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)




view thread (9+ messages)  latest in thread

Message-ID: <144D12D7DD4EC04F99241498BB4EEDCC220D19@nelson.osl.com>
Permalink:  ../144D12D7DD4EC04F99241498BB4EEDCC220D19@nelson.osl.com/
Also on:    postgresql.org/message-id/144D12D7DD4EC04F99241498BB4EEDCC220D19@nelson.osl.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ojacobson@osl.com
  Subject: Re: Given 02-01-2006 to 02-28-2006, output all days.
  In-Reply-To: <144D12D7DD4EC04F99241498BB4EEDCC220D19@nelson.osl.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox