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: subtracting date / time in SQL

Re: subtracting date / time in SQL

From: Connor McDonald <connor_mcdonald_at_yahoo.com>
Date: Tue, 12 Jun 2001 22:32:21 +0100
Message-ID: <3B268A65.1070103@yahoo.com>

Syltrem wrote:

> I am trying to calculate the elapsed time for a connected session
> Example:
> select sysdate - logon_time from v$session where sid=35;
>
> SYSDATE-LOGON_TIME
> ------------------
> ,278344907
>
> Which is approximately 6 hours (a quarter of a day).
>
> Now I want to display this in time format, I tried the following
> select to_char(sysdate - logon_time, 'HH:MI:SS') from v$session where
> sid=35
> *
> ERROR at line 1:
> ORA-01481: invalid number format model
>
> and also this
> select to_char(to_date(sysdate - logon_time), 'HH:MI:SS') from v$session
> where sid=35;
>
> What am I doing wrong?
>
> Thanks for helping me!
> --
>
> Syltrem
> http://pages.infinit.net/syltrem (OpenVMS related web site)
> To reply to myself directly, remove .spammenot from my address
>
>
>

Subtracting two dates gives a number - if the result is

xxx.yyy

then xxx is the days, 0.yyy is the part of a day, so 24 * 0.yyy is hours, and so forth

hth
connor

-- 
==============================
Connor McDonald

http://www.oracledba.co.uk

"Some days you're the pigeon, some days you're the statue..."
Received on Tue Jun 12 2001 - 16:32:21 CDT

Original text of this message

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