Re: PL/SQL Function about dates

From: Ian Cary <cary_at_gatwick.geco-prakla.slb.com>
Date: 1997/12/05
Message-ID: <3487F74D.23323A1A_at_gatwick.geco-prakla.slb.com>#1/1


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;

  begin
  diff := date1 -date2;
  return diff;
  end;

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 CET

Original text of this message