From: | José Soares <jose(at)sferacarta(dot)com> |
---|---|
To: | "Pham, Thinh" <tpham(at)mail(dot)priority(dot)net> |
Cc: | "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgreSQL(dot)org> |
Subject: | Re: [SQL] datetime function |
Date: | 1999-06-04 14:51:58 |
Message-ID: | 3757E80E.7A92835F@sferacarta.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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'
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 1999-06-04 15:06:04 | Re: [SQL] RV: A little problem updating data with views |
Previous Message | Tom Lane | 1999-06-04 14:33:18 | Re: [SQL] Mail about select |