As the title suggested , I am looking for a function in pl /sql which does something similar like the DateAdd function. I have been looking and I found the add_months function but I would really like one that is a little more variable since I need to be able to add minutes, hours , days etc.
It appears there's not many solutions :
PL/SQL allows you to perform arithmetic operations directly on date variables. You may add numbers to a date or subtract numbers from a date. To move a date one day in the future, simply add 1 to the date as shown below:
hire_date + 1
You can even add a fractional value to a date. For example, adding 1/24 to a date adds an hour to the time component of that value. Adding 1/(24*60) adds a single minute to the time component, and so on.
Besides adding numbers to dates - though it's the simplest way - you can add intervals like that:
date1 := date2 + interval '1' day;
date1 := date2 + interval '2' month;
date1 := date2 + interval '3' year;
It's almost the same but I prefer latter for better readability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With