Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: PL/SQL Function about dates
Acácio Nuno wrote:
> I need to kown the number of days between two dates, if you have a
> function that accepts these
> 2 dates as parameters and returns the number of days between them,
> pleaaaaaase send me!
You can perform standard arithmetic on dates therefore the function:-
create or replace function date_diff(date1 date, date2 date)
return number as diff number;
should do the trick. e.g.
select date_diff(sysdate,'01-DEC-97') from dual 2 /
DATE_DIFF(SYSDATE,'01-DEC-97')
4.5297338
The reason for the trailing decimals is due to the time element of sysdate. You can remove this if required by using trunc but I'll leave it you to decide the input date format and the precision of the output.
Regards,
Ian Received on Fri Dec 05 1997 - 00:00:00 CST
![]() |
![]() |