Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Date Arithmetic
Nirmalya,
You can try this function. It takes seconds as a parameter and displays the results in a formatted string.
Function Second_Convert(in_sec in number)
return varchar2 is
hrs number;
lmin number;
sec number;
ret_string varchar2(40);
--in_sec number := 3670;
begin
hrs := trunc(in_sec / (60*60));
lmin := trunc((in_sec - (hrs * 60*60))/60);
sec := in_sec - ((hrs * 60 * 60) + (lmin * 60));
ret_string := lpad(hrs,2,'0') || ':' || lpad(lmin,2,'0') || ':' ||
lpad(sec,2,'0');
-- dbms_output.put_line ('hhmiss=' || hrs || ':' || lmin || ':' ||
sec);
return ret_string;
end;
So you could call it as:
Select second_convert((sysdate-flush_stamp)*3600*24) from dual
Feel free to change the function any way you wish.
Tom
-----Original Message-----
From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Nirmalya Das
Sent: Friday, July 14, 2006 12:46 PM
To: oracle-l_at_freelists.org
Subject: Date Arithmetic
Hi All,
I am trying to find the "number of minutes" between "sysdate" and
"flush_stamp".
I have the following query which works, but would like to find out if
anyone has
more elegant way of doing this using oracle functions like "EXTRACT" or
"INTERVAL" etc.
select to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss') "Now", to_char(flush_stamp,'mm/dd/yyyy hh24:mi:ss') as "Flush Time",
trunc((86400*(sysdate-flush_stamp))/60)-60*(trunc(((86400*(sysdate-flush
_stamp))/60)/60))
as "Mins",
trunc(((86400*(sysdate-flush_stamp))/60)/60)-24*(trunc((((86400*(sysdate
-flush_stamp))/60)/60)/24))
"Hrs",
trunc((((86400*(sysdate-flush_stamp))/60)/60)/24) "Days", ((1440*trunc((((86400*(sysdate-flush_stamp))/60)/60)/24)))+
(60*trunc(((86400*(sysdate-flush_stamp))/60)/60)-24*(trunc((((86400*(sys date-flush_stamp))/60)/60)/24)))+
(trunc((86400*(sysdate-flush_stamp))/60)-60*(trunc(((86400*(sysdate-flus h_stamp))/60)/60))
) as "Tot Mins"
from mega_owner_01.ia_ora_log
where ((1440*trunc((((86400*(sysdate-flush_stamp))/60)/60)/24)))+
(60*trunc(((86400*(sysdate-flush_stamp))/60)/60)-24*(trunc((((86400*(sys date-flush_stamp))/60)/60)/24)))+
(trunc((86400*(sysdate-flush_stamp))/60)-60*(trunc(((86400*(sysdate-flus
h_stamp))/60)/60)))
> 500
"Now" "Flush Time" "Mins" "Hrs" "Days"
"Tot Mins"
"07/14/2006 09:43:27" "07/14/2006 01:17:14" "26" "8" "0"
"506"
"07/14/2006 09:43:27" "07/14/2006 01:58:20" "45" "7" "0"
"465"
TIA Nirmalya
-- http://www.freelists.org/webpage/oracle-l -- http://www.freelists.org/webpage/oracle-lReceived on Fri Jul 14 2006 - 12:16:27 CDT
![]() |
![]() |