Thread: Comparing dates in 3.0

Comparing dates in 3.0

From
Ellen Spertus
Date:
After upgrading from 6.x to 7.x, the following query broke, I lost the
ability to check how many days apart two DATEs are by subtracting
them.  What is the correct way to determine the difference between two
dates in 7.x?

Thank you.

Ellen Spertus


RE: Comparing dates in 3.0

From
"Francis Solomon"
Date:
Hi Ellen,

Subtracting one timestamp from another returns an interval type, like
this:

stasis=# select 'now'::timestamp - '10 Sep 2000'::timestamp;
  ?column?
-------------
 75 12:06:57
(1 row)

But if you just want the days only, try this:

stasis=# select date_part('days', 'now'::timestamp - '10 Sep
2000'::timestamp);
 date_part
-----------
        75
(1 row)

Hope this helps.

Regards

Francis

> -----Original Message-----
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org]On Behalf Of Ellen Spertus
> Sent: 17 November 2000 04:39
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] Comparing dates in 3.0
>
>
> After upgrading from 6.x to 7.x, the following query broke, I
> lost the
> ability to check how many days apart two DATEs are by subtracting
> them.  What is the correct way to determine the difference
> between two
> dates in 7.x?
>
> Thank you.
>
> Ellen Spertus
>
>