Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Compute difference between timestamps

Re: Compute difference between timestamps

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Sun, 4 Jun 2006 07:56:07 +0200
Message-ID: <448275f5$0$20866$626a54ce@news.free.fr>

<c8s3dw_at_verizon.net> a écrit dans le message de news: 1149377499.120834.262480_at_j55g2000cwa.googlegroups.com...
| so I do that:
|
| SQL> create table t ( t1 timestamp, t2 timestamp );
|
| Table created.
|
| SQL> insert into t ( t1 ) values ( systimestamp );
|
| 1 row created.
|
| SQL> update t set t2 = systimestamp;
|
| 1 row updated.
|
| and get an interval, which is not what I asked for:
|
| SQL> select ( t2 - t1 ) / ( 24 * 60 * 60 ) from t;
|
| (T2-T1)/(24*60*60)
| ---------------------------------------------------------------------------
| +000000000 00:00:00.000297303
|

So the real question is not "how to compute a difference between timestamps" but how to convert a day to second interval into seconds:

SQL> create table t ( t1 timestamp, t2 timestamp );

Table created.

SQL> insert into t ( t1 ) values ( systimestamp );

1 row created.

SQL> exec dbms_lock.sleep (10.23);

PL/SQL procedure successfully completed.

SQL> update t set t2 = systimestamp;

1 row updated.

SQL> commit;

Commit complete.

SQL> select t2-t1 d1, to_char(extract(second from t2-t1),'990.000') d2 from t;

D1                                   D2
------------------------------ --------
+000000000 00:00:26.719000       26.719

1 row selected.

Regards
Michel Cadot Received on Sun Jun 04 2006 - 00:56:07 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US