Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Anyone have a DAYS_BETWEEN function?
The theory of finding the amount of days between ranges is pretty simple.
Julian dates are defined as the amount of days since the 1st of January 4712
BC. Therefore, convert both your dates to julian and subtract one from the
other. I'll supply a function i knocked together that does it.
To answer your other question about ADD_TO_DATE, try something along the lines of:
select sysdate +100 from dual;
This will add 100 days to todays date. Just replace sysdate with the date variable of your choice in your function (not forgetting to to a to_char(to_date(...,...)) on your inputted date variable).
Other date tweaking functions you want to define can follow this lead.
Regards,
Mark
Create or replace Function Days_Between (v_from_date in varchar2, v_to_date in varchar2) return number is
v_julian_date_from number;
v_julian_date_to number;
begin
select to_char(to_date(v_from_date,'DD-MON-YYYY'), 'j')
into v_julian_date_from
from dual;
select to_char(to_date(v_to_date,'DD-MON-YYYY'), 'j')
into v_julian_date_to
from dual;
return (v_julian_date_to - v_julian_date_from);
end;
cjdavies1999_at_my-dejanews.com wrote in message <7bi9m6$2m8$1_at_nnrp1.dejanews.com>...
>I am looking for a DAYS_BETWEEN function, similar to the MONTHS_BETWEEN >function provided by Oracle. I would also like to be able to have a more >general form of the ADD_MONTHS function, something like ADD_TO_DATE( >date_to_increment, increment ammount, increment_unit). > >I welcome any pointers to Web sites where I can find date functions forOracle
>would be greatly appreciated. > >-----------== Posted via Deja News, The Discussion Network ==---------- >http://www.dejanews.com/ Search, Read, Discuss, or Start Your OwnReceived on Wed Mar 03 1999 - 09:33:01 CST