Oracle PL/SQL - Date type MONTHS_BETWEEN function


The MONTHS_BETWEEN function is shown here:

v_nr:= MONTHS_BETWEEN(date1,date2);

This function returns the number of months between two dates.

If this difference is not exact, you get a floating-point number where the decimal portion represents the fraction N/31 where N is the number of remaining days.

If SYSDATE were near the beginning of February, you would get results similar to those shown here:


SQL> declare-- from   w w w .ja  v  a2  s.c  o  m
  2       v_nr number;
  3  begin
  4      v_nr:=months_between(sysdate,trunc(sysdate,'Y'));
  5      DBMS_OUTPUT.put_line(v_nr);
  6  end;
  7  /

PL/SQL procedure successfully completed.


Related Topic