pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris <dmagick@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: getting extract to always return number of hours
Date: Wed, 06 Jan 2010 13:48:33 +1100
Message-ID: <4B43FA01.2030406@gmail.com> (raw)
In-Reply-To: <4B43E887.6040402@gmail.com>
References: <4B43E887.6040402@gmail.com>

Chris wrote:
> Hi,
> 
> I'm trying to get extract() to always return the number of hours between 
> two time intervals, ala:
> 
> => create table t1(timestart timestamp, timeend timestamp);
> => insert into t1(timestart, timeend) values ('2010-01-01 00:00:00', 
> '2010-01-02 01:00:00');
> 
> => select timeend - timestart from t1;
>     ?column?
> ----------------
>  1 day 01:00:00
> (1 row)
> 
> to return 25 hours.

I ended up with

select extract('days' from x) * 24 + extract('hours' from x) from 
(select (timeend - timestart) as x from t1) as y;

mainly because t1 is rather large so I didn't want to run the end - 
start calculation multiple times.

-- 
Postgresql & php tutorials
http://www.designmagick.com/




view thread (3+ messages)

Message-ID: <4B43FA01.2030406@gmail.com>
Permalink:  ../4B43FA01.2030406@gmail.com/
Also on:    postgresql.org/message-id/4B43FA01.2030406@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dmagick@gmail.com
  Subject: Re: getting extract to always return number of hours
  In-Reply-To: <4B43FA01.2030406@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox