From sfaroult@oriolecorp.com Tue, 10 Jul 2001 08:34:05 -0700 From: Stephane Faroult Date: Tue, 10 Jul 2001 08:34:05 -0700 Subject: Re: Date / Time Message-ID: MIME-Version: 1.0 Content-Type: text/plain Sajid Iqbal wrote: > > Hello All > > I want to display the "time elapsed" between two dates - in days, hours, > minutes and seconds. > > If I do "select date1 - date2", the result is : 12.0194907 > > Is there a function that will turn the number of days into something more > legible? Ideally i'd like to do ; > > "to_char(12.0194907,'DD:HH:MI:SS')" but obviously that won't work. Is > there a solution other than writing a complex function myself which will > have to * by 24, / by 60 and substr etc to get the different bits of the > number? > > Please CC any replies directly to me at siqbal@vianetworks.co.uk > > Thanks in advance, > Saj. > > -- > Sajid Iqbal > Database Team Leader Sajid, The difference of two dates is a number of days. If you want to use a function similar to the dates function, you have to treat the day and fractional parts separately, eg select trunc(date2 - date1) days, to_char(trunc(sysdate) + (date2 - date1) - trunc(date2 - date1), 'HH24:MI') This uses a trick, the fact that date + number is a date ('number' is assumed to be a number of days) - so we can use 0:00 today as 'base' and just display hours and minutes (and seconds if you need them). -- Regards, Stephane Faroult Oriole Corporation ------------------------------------------------------------------ http://www.oriolecorp.com, designed by Oracle DBAs for Oracle DBAs ------------------------------------------------------------------ -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Stephane Faroult INET: sfaroult@oriolecorp.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru@fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).