Re: getting extract to always return number of hours

Поиск
Список
Период
Сортировка
От Chris
Тема Re: getting extract to always return number of hours
Дата
Msg-id 4B43FA01.2030406@gmail.com
обсуждение исходный текст
Ответ на getting extract to always return number of hours  (Chris <dmagick@gmail.com>)
Список pgsql-sql
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/



В списке pgsql-sql по дате отправления:

Предыдущее
От: Rosser Schwarz
Дата:
Сообщение: Re: getting extract to always return number of hours
Следующее
От: John Summerfield
Дата:
Сообщение: Re: Proper case function