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

Home -> Community -> Usenet -> c.d.o.server -> Re: Is there a dateadd() function?

Re: Is there a dateadd() function?

From: Jeremy Ovenden <jovenden_at_hazelweb.co.uk>
Date: Tue, 21 Jul 1998 22:10:25 +0100
Message-ID: <35B503C1.285827A6@hazelweb.co.uk>


Good, I follow that. The whole problem though, is e.g.

    date_early = '21-dec-1997 21:06:32'     date_later = '21-dec-1997 22:08:00'

The results you have descibe appear to be just whole days (?) and hence units of 24 hours etc. The result I requires is, from the above example, the number of seconds that have elapsed between date_early to date_late -- that is 1h, 1m, 28s or 3698 seconds. Can this be done (am I missing something very obvious here??).

Cheers
Jeremy

Arjan van Bentem wrote:

> Easy enough:
>
> (date2 - date1) = days
> (date2 - date1) * 24 = hours
>
> Get the picture?
>
> (date2 - date1) * 24 * 60 = minutes
> (date2 - date1) * 24 * 60 * 60 = seconds
>
> By the way, to print the difference in readable HH:MI:SS format (where HH
> could be > 23 if the difference is more than one day), try something like
>
> to_char( trunc( (date2 - date1) * 24 ) || ':' ||
> to_char( mod( abs(date2 - date1) * 24 * 60, 60 ) , 'FM00') || ':' ||
> to_char( mod( abs(date2 - date1) * 24 * 60 * 60, 60) , 'FM00')
>
> I am not sure if FM00 is allowed in Oracle 7.3 and earlier. It prevents
> Oracle from printing a leading blank when there is no minus sign. If you
> can't use it, try lpad( to_char( ..), 2, '0') instead.
>
> Arjan.
Received on Tue Jul 21 1998 - 16:10:25 CDT

Original text of this message

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