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.
A:
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.
MatTheCat
2010-10-25 08:41:07
mmm ok. So only workarounds in this area huh;). Thanks for the advice , I will give it a try.
jovany
2010-10-25 08:59:47
It's all I found even if it seems weird to me. I'm a MySQL user ^^
MatTheCat
2010-10-25 09:03:49
Workaround? Guess that depends on where you come from. Being used to simple arithmetic you might wonder why on earth you need a special function to add a value to a date.
Rene
2010-10-25 10:37:03
+2
A:
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.
andr
2010-10-25 10:37:04