Re: Calculating Differences Between Dates - Problem

From: Simon Mitchell <pgsql(at)jseb(dot)com>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Calculating Differences Between Dates - Problem
Date: 2003-01-10 21:17:23
Message-ID: 3E1F3863.50906@jseb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Just subtract the dates from each other works ok for me.

psql=# select
to_date('2002-12-16','YYYY-MM-DD')-to_date('2002-10-29','YYYY-MM-DD');
?column?
----------
48
(1 row)

or
psql=# select
to_date('2002-12-16','YYYY-MM-DD')-to_date('1999-10-29','YYYY-MM-DD') as
days ;
days
------
1144
(1 row)

Simon
Bruno Wolff III wrote:

>On Fri, Jan 10, 2003 at 12:35:37 -0800,
> Hunter Hillegas <lists(at)lastonepicked(dot)com> wrote:
>
>
>>I am trying to calculate the number of days between two dates.
>>
>>
>
>Just subtract the dates from each other. The result will be an integer type
>with the number of days between the two dates.
>
>
>
>>date_shipped: 2002-12-16
>>date_of_request: 2002-10-29
>>date_difference: 18
>>NOT OK - it is more days than this.
>>
>>
>
>You are just comparing the days of the month, not the actual days.
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2003-01-10 21:41:46 SCO 5.0.4 Compilation
Previous Message Bruno Wolff III 2003-01-10 21:02:58 Re: Calculating Differences Between Dates - Problem