Re: Determining period between 2 dates - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Determining period between 2 dates
Date
Msg-id AANLkTim7qp3QsdsvMiUq_uTnMi2g+BENYiYbS6f5z2Vm@mail.gmail.com
Whole thread Raw
In response to Determining period between 2 dates  (Thom Brown <thom@linux.com>)
Responses Re: Determining period between 2 dates  (Jan-Benedict Glaw <jbglaw@lug-owl.de>)
List pgsql-hackers
On Wed, Feb 16, 2011 at 10:47 AM, Thom Brown <thom@linux.com> wrote:
> Hi all,
>
> I'm wondering what people think of introducing some kind of function
> to extract the number of units between 2 dates?  At the moment there's
> no way to do this.  Take the following example:
>
> Event 1 is '1985-10-26 01:22:00'
> Event 2 is now.
>
> How many minutes between these 2 events?  What I don't want is how
> many years, months, days and hours there are between them.
>
> This could potentially involve implementing age(timestamp, timestamp,
> interval), like:
>
> postgres=# SELECT age(current_date, '1985-10-26 01:22:00'::timestamp,
> '1 second') as age_in_seconds;
>  age_in_seconds
> ----------------
>      798733367
> (1 row)
>
>  Is this easily done?

How about something like this:

rhaas=# select (extract('epoch' from now()) - extract('epoch' from
timestamptz '1985-10-26 01:22:00')) / 60;    ?column?
------------------13311989.7435394
(1 row)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-hackers by date:

Previous
From: Thom Brown
Date:
Subject: Determining period between 2 dates
Next
From: Jan-Benedict Glaw
Date:
Subject: Re: Determining period between 2 dates