I am new in SQL area. Could someone over there tell me there is a function in
SQL to calculate days between two dates? For example, how many days between
Jan. 23 1995 and Feb. 1 1996? I haven't found any function calculating days
directly. I know I could write a pices of program to implement this, but
I hope if there is such function I can just call.
Thank you very much.
Jiang Hong
Just subtract the two date values.
For example:
SELECT SYSDATE - TO_DATE('03-02-1996','MM-DD-YYYY') FROM dual;
The result is fractional in days.
This example is Oracle specific. Date handling tends to vary
between database vendors. For example, Ingres also allows
subtraction, but returns a special data type called an 'Interval'.
Regards,
Mark Rosenthal
--
Scott Urman
"The opinions expressed here are my own, and are not necessarily that of
Oracle Corporation"
Oracle's PL/SQL supports a full set of date operators. There are
many ways of finding the days between 2 dates. The simplest is
x := trunc(date1) - trunc(date2);
The trunc will set the hours:minutes:seconds to 12:00:00 for the
variables date1 and date2. Both these variables should be declared
as date.
Gene Maillet
select months_between(date_1, date_2) * 31 from dual;
If DATE_1 is later than DATE_2 the result is positive, else its negative.
Regards,
Ron Evans
ADVANCED SYSTEMS GROUP
ASG...@AOL.COM
Ron Evans
ASG...@AOL.COM
subtract two dates and the value is a decimal giving days between the
dates.
ie select date1-date2 from table;
>directly. I know I could write a pices of program to implement this, but
>I hope if there is such function I can just call.
>
>Thank you very much.
>
>Jiang Hong
regards Geoff Ingram
----------------------------
All my own personal opinions