pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: José Soares <jose@sferacarta.com>
To: Pham, Thinh <tpham@mail.priority.net>
Cc: 'pgsql-sql@postgresql.org' <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] datetime function
Date: Fri, 04 Jun 1999 16:51:58 +0200
Message-ID: <3757E80E.7A92835F@sferacarta.com> (raw)
References: <551413BBBB03D111BF880060B01AACCE0B38F2@home.priority.net>

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'

view thread (2+ messages)

Message-ID: <3757E80E.7A92835F@sferacarta.com>
Permalink:  ../3757E80E.7A92835F@sferacarta.com/
Also on:    postgresql.org/message-id/3757E80E.7A92835F@sferacarta.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: jose@sferacarta.com, tpham@mail.priority.net
  Subject: Re: [SQL] datetime function
  In-Reply-To: <3757E80E.7A92835F@sferacarta.com>
  References: <551413BBBB03D111BF880060B01AACCE0B38F2@home.priority.net> <3757E80E.7A92835F@sferacarta.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