datetime function

Поиск
Список
Период
Сортировка
Искать

datetime function

От:
"Pham, Thinh" <tpham@mail.priority.net>
Дата:
Is there any sql92 functions (not really essential) that calculates the
timespan between 2 separate points in time? For example, i want to calculate
the total minutes between 2:30pm and 3:30pm. There's a function like this in
microsoft sql but i can't find it in postgres. Below is how it works in ms:

DATEDIFF(minute, '14:30', '15:30')

I looked at the "timespan" function but it's not the same one that i need.
Thanks,
Thinh

Re: [SQL] datetime function

От:
José Soares <jose@sferacarta.com>
Дата:
In SQL/92:

prova=> select CURRENT_TIME as now, time '18:50:00' - current_time as diff;
now     |diff
--------+--------
18:47:48|00:02:12
(1 row)
 

To have this in PostgreSQL create a PL/pgSQL function like:

create function time_mi_time(time,time) returns timespan as
'
declare
        i1 interval;
        i2 interval;
begin
        i1:= $1;
        i2:= $2;
        i1:=i1 - i2;
        return i1;
end;
' language 'plpgsql';

create operator - (
        leftarg=time,
        rightarg=time,
        procedure=time_mi_time,
        commutator='-',
        negator='+',
        restrict=eqsel,
        join=eqjoinsel
        );
 

"Pham, Thinh" ha scritto:

Is there any sql92 functions (not really essential) that calculates the
timespan between 2 separate points in time? For example, i want to calculate
the total minutes between 2:30pm and 3:30pm. There's a function like this in
microsoft sql but i can't find it in postgres. Below is how it works in ms:

DATEDIFF(minute, '14:30', '15:30')

I looked at the "timespan" function but it's not the same one that i need.
Thanks,
Thinh

--
______________________________________________________________
PostgreSQL 6.5.0 on i586-pc-linux-gnu, compiled by gcc 2.7.2.3
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jose'
 
FAQ