Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How to calculate difference in time?
A copy of this was sent to robertch_at_mindspring.com (Robert Chung)
(if that email address didn't require changing)
On Mon, 31 Aug 1998 22:05:52 GMT, you wrote:
>
>Does anyone know how to calculate difference in time? Following is
>something that I tried.
>
>declare
> date_X date;
> date_Y date;
>begin
> date_X:=SYSDATE;
>
> -- Do something. Spend some time
>
> date_Y:=SYSDATE;
> dbms_output.put_line(
> to_char(date_Y-date_X,
> 'MM:DD:YYYY HH24:MI:SS'));
>end;
>/
>
when you substract two dates from eachother, you get the difference between the two in DAYS (down to the second level). For example:
1* select sysdate - to_date( '02-sep-1998 12', 'dd-mon-yyyy hh24' ) from dual SQL> / SYSDATE-TO_DATE('02-SEP-199812','DD-MON-YYYYHH24')
-.11574074SQL> select .11574047*24 HOURS from dual;
HOURS
so, when I ran this query, 11/100's of a day was the difference (about 2.7777 hours).
If you want to time down to the HSECs, the easiest thing to do tho is:
...
begin
start_time := dbms_utility.get_time;
.... do something ...
end_time := dbms_utility.get_time;
dbms_output.put_line( end_time-start_time || ' hsecs have elapsed...' );
end;
....
>Following is the output that I got.
>
>Statement processed.
>##########
>
>All I want is the difference in time (possibly to the micro second).
>Is there any way to do it? Thank you.
Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA
--
http://govt.us.oracle.com/ -- downloadable utilities
Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Wed Sep 02 1998 - 08:37:43 CDT