7-3. Adding a Number of Months to a Date
Problem
You want to add some number of months to a date. For example, you are developing a payment application for a company, and it requires payments every six months. You need to enable the application to calculate the date six months in the future of the current date.
Note This recipe's solution also works for subtracting months. Simply “add” a negative number of months.
Solution
Use the ADD_MONTHS
function to add six months onto the given date. Doing so will enable your application to create bills for future payments. This technique is demonstrated in the following example:
DECLARE new_date DATE; ...
Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.