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: format difference of dates as date

Re: format difference of dates as date

From: Ken Denny <ken_at_kendenny.com>
Date: 5 Apr 2005 08:00:34 -0700
Message-ID: <1112713234.580242.190180@z14g2000cwz.googlegroups.com>


Tobias Wagner wrote:
> Rauf Sarwar wrote:
> > You would have to do this in a PLSQL function that takes end_date
and
> > start_date and returns varchar2 as 'DD HH24:MI:SS'.
> >
> > Hint: (end_date - start_date) * 86400 will give you date difference
in
> > seconds. 86400 are number of seconds in a 24 hour period. Now you
can
> > do the math.
>
> Isn't there a way to cast a number to a date and then use the regular

> to_char function?
> Can't I add the difference of start- and endtime to some kind of
"zero"
> date?
>
> Cheers,
> Tobi

You'll have to separate out the number of whole days, then you can express the time difference as a time.

datediff := ABS(date_1 - date_2)
wholedays := floor(datediff);
varchar_diff := wholedays || ' '||

   to_char(trunc(sysdate)+(datediff - wholedays),'HH24:MI:SS');

Ken Denny Received on Tue Apr 05 2005 - 10:00:34 CDT

Original text of this message

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