pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
datetime function
2+ messages / 2 participants
[nested] [flat]

* datetime function
@ 1999-06-01 20:25 Pham, Thinh <tpham@mail.priority.net>
  1999-06-04 14:51 ` Re: [SQL] datetime function José Soares <jose@sferacarta.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Pham, Thinh @ 1999-06-01 20:25 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [SQL] datetime function
  1999-06-01 20:25 datetime function Pham, Thinh <tpham@mail.priority.net>
@ 1999-06-04 14:51 ` José Soares <jose@sferacarta.com>
  0 siblings, 0 replies; 2+ messages in thread

From: José Soares @ 1999-06-04 14:51 UTC (permalink / raw)
  To: Pham, Thinh <tpham@mail.priority.net>; +Cc: 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'

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1999-06-04 14:51 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-06-01 20:25 datetime function Pham, Thinh <tpham@mail.priority.net>
1999-06-04 14:51 ` José Soares <jose@sferacarta.com>

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