In Oracle, add_months() function is used to return date with specified months added for the future date and if specified months is negative value then subtracted for past date.
Syntax
Add_Months(date, number_of_months);
Add_Months Function Example
1. To get Future Date, use add_months function with the positive number of months value.
SELECT ADD_MONTHS (SYSDATE, 5) FROM DUAL;
Output
ADD_MONTHS(SYSDATE,5) --------------------- 12-DEC-18 1 row selected.
The current date is 12th July 18, so after adding 5 months the result is 12th Dec 18.
2. To get past date, specify the number of months in the negative value.
SELECT ADD_MONTHS (SYSDATE, -5) FROM DUAL;
Output
ADD_MONTHS(SYSDATE,-5) ---------------------- 12-FEB-18 1 row selected.
See also:
- Get Previous Months Data using Add_Months function
- Get Number of days between two dates
- Finding difference between two date parts