Skip site navigation (1) Skip section navigation (2)

Re: How cast interval to minutes as number?

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: How cast interval to minutes as number?
Date: 2007-11-25 08:53:22
Message-ID: 20071125085321.GA20882@KanotixBox (view raw or flat)
Thread:
Lists: pgsql-novice
Andreas <maps(dot)on(at)gmx(dot)net> schrieb:

> Hi,
> 
> I have a column with timestamps  --> some_ts  .
> I'd like to calculate the amount of time between this timestamp and NOW().
> 
> select   some_ts - NOW()   from some_table;
> 
> This results in a column of type  interval.
>  How would I get this interval converted into e.g. minutes.

Okay, lets assume i want to know how old is my daughter, in minutes:

test=# select EXTRACT (EPOCH FROM  now() - '2007-07-28 09:15:00'::timestamp )::int/60;
 ?column?
----------
   172896
(1 row)

You can exchange the fix timestamp with a column from a table, no
problem.


Hope that helps, Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

In response to

Responses

pgsql-novice by date

Next:From: AndreasDate: 2007-11-25 09:03:19
Subject: Re: How cast interval to minutes as number?
Previous:From: Maximilian TyrtaniaDate: 2007-11-25 08:32:12
Subject: Re: How cast interval to minutes as number?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group