Re: Another date / time question

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Vanole, Mike" <mike(dot)vanole(at)attws(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Another date / time question
Date: 2004-03-26 20:42:12
Message-ID: 20040326204212.GD20194@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Mar 26, 2004 at 12:21:59 -0500,
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Vanole, Mike" <mike(dot)vanole(at)attws(dot)com> writes:
> > I'm trying to query two timestamp(0) columns to determine elapsed time. I u=
> > se the age() function which works fine, but I want to return the informatio=
> > n in MINUTES.=20
>
> Just subtract (giving an interval), use extract(epoch) to get the
> interval in seconds, then divide by 60 and round (or truncate if you
> prefer).

To expand on this, while age returns an interval, it will include
a months part in the interval (if the timestamps are over of month apart)
and this will mess up your calculation. When you just subtract, you will
get an absolute time difference that you can reliably convert to minutes.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jack Orenstein 2004-03-26 20:43:56 Inserts get slower as table gets bigger
Previous Message Diogo Biazus 2004-03-26 20:29:21 Problem with memory in C function