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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Subtracting Dates

Re: Subtracting Dates

From: programmer <int.consultNOCAPITALS_at_macmail.com>
Date: Tue, 29 Jul 2003 17:05:51 +0100
Message-ID: <bg66g6$ki0$1@pheidippides.axion.bt.co.uk>

> I need to show the difference between dates in format: hh24:mi:ss.
>

Like this:

create table datesub(time1 date, time2 date);

insert into datesub
values (to_date('20030703 123456','yyyymmdd hh24miss'),to_date('20030707 082334','yyyymmdd hh24miss'));

insert into datesub
values (to_date('20030703 123456','yyyymmdd hh24miss'),to_date('20030701 082334','yyyymmdd hh24miss'));

select floor(time2-time1) || ' day(s) ' || to_char(to_date('20000101','yyyymmdd') + (time2-time1),'hh24:mi:ss') as diff from datesub
where time2 >= time1
union
select '-' || floor(time1-time2) || ' day(s) ' || to_char(to_date('20000101','yyyymmdd') + (time1-time2),'hh24:mi:ss') as diff from datesub
where time1 >= time2;

The "to_date('0','ss')" is added to convert the difference (which is a number) to a date. The date doesn't matter but the time part is needed. Received on Tue Jul 29 2003 - 11:05:51 CDT

Original text of this message

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