Calculating Differences Between Dates - Problem

From: Hunter Hillegas <lists(at)lastonepicked(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Calculating Differences Between Dates - Problem
Date: 2003-01-10 20:35:37
Message-ID: BA446E99.898BB%lists@lastonepicked.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am trying to calculate the number of days between two dates.

Right now I have this query fragment:

date_part('day'::text,
age(timestamptz(sample_request_line_item.date_shipped),
sample_request.date_of_request)) AS date_difference

This works as long as the date doesn't span the month. In those cases I get
bad values. i.e.:

date_shipped: 2003-01-10
date_of_request: 2003-01-09
date_difference: -1
OK

date_shipped: 2003-01-10
date_of_request: 2003-01-09
date_difference: -1
OK

date_shipped: 2002-12-16
date_of_request: 2002-10-29
date_difference: 18
NOT OK - it is more days than this.

Looks like I am just not printing out the month as well as the day
difference... But I need it all translated into days, not month(s)+days(s).
Can I do this?

Thanks,
Hunter

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ian Harding 2003-01-10 21:01:10 Demo System...
Previous Message Iker Arizmendi 2003-01-10 20:16:23 Re: rfc - libpq extensions