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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: How cast interval to minutes as number?



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°



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group