Re: Oracle Dates in Sqlplus

From: Marcel Claus <Marcel.Claus_at_Informatik.Uni-Oldenburg.DE>
Date: 1997/10/10
Message-ID: <61kp93$mtt_at_news.Informatik.Uni-Oldenburg.DE>#1/1


Bob Johnson wrote:

> David Power wrote:
> >
> > Does anyone know how to get the difference between two oracle
> > datetimes in minutes using SQL.
> >
> > David Power.
>
> Yes

And here is another one... There are so many people having questions aboutdate/time conversions.
Here some general things:
date is always in days, so sysdate + 1 means tomorrow (same hour, minute,
second) and sysdate + (x * (1/24)) means now plus x hours. You can do this also with to seconds:

sysdate + (x * (1/(24 * 60 *60))) is now plus x seconds.

If you want to get the difference between two times convert the attributes to
seconds and work with them:

to_number(to_char(time_a, 'SSSSS')) - to_number(to_char(time_b, 'SSSSS')) But always remeber: SSSSS returns seconds since midnight! So be sure you do
not have stored different days in time_a and time_b. If you want to have the difference over more than 24 hours you have first get
the difference in days, multiply this with 24*60*60 and add the difference in
seconds to get the seconds between two date (convert this to hours, minutes
or somethin else):

to_number(time_a - time_b) * 24*60*60 +
to_number(to_char(time_a, 'SSSSS')) - to_number(to_char(time_b, 'SSSSS')) Maybe someone could set this to a general read-me-about-dates ????

Marcel Received on Fri Oct 10 1997 - 00:00:00 CEST

Original text of this message