Date Duration Numbers

From: John Nix <maximum(at)shreve(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Date Duration Numbers
Date: 2002-07-09 17:24:51
Message-ID: Pine.LNX.4.44.0207091214520.28748-100000@server.sblug.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


I have a problem, I need to find out how many days there are between 2
date fields and then add all the dates up.

Example...

name | start_date | end_date
------+------------+------------
Joe1 | 2002-01-01 | 2002-01-02
Joe2 | 2002-01-01 | 2002-01-03
Joe3 | 2002-01-01 | 2002-01-04
Joe4 | 2002-01-01 | 2002-01-05
Joe5 | 2002-01-01 | 2002-01-06

As you can see, the duration is:

Joe1 - 1 day
Joe2 - 2 days
Joe3 - 3 days
Joe4 - 4 days
Joe5 - 5 days

Now that I have the duration between the times, I need to add up all those
numbers:

1 day
2 days
3 days
4 days
+ 5 days
----------
15 days

I can use age() to get my interval (select age(date '2002-01-02', date
'2002-01-01')), but I can't seem to use the field names with that, I have
to manually enter in all the dates. I have about 900 entries in this
table. Is there a way to do this? Thanks...

John

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-07-09 17:36:52 Re: Date Duration Numbers
Previous Message Stephan Szabo 2002-07-09 16:48:38 Re: update problem?