How can we add two dates in oracle? For example in sql we can do this, " date_1 + date_2 " how can we achieve the same thing in Oracle
Asked
Active
Viewed 8,510 times
-2
-
2How do you define the sum of two date? What should one expect from `'1999-12-31' + '2012-10-18'`? – ypercubeᵀᴹ Oct 18 '12 at 12:44
-
1What `sql` are you referring to? Adding two dates is meaningless. You can add an interval to a date. – Alex Oct 18 '12 at 12:44
-
What the result you want by summing 2 dates? – Marc Oct 18 '12 at 12:44
-
Which is the expected result when adding two dates? How would you add dates? – GuiGi Oct 18 '12 at 12:45
-
the right way is to convert 1 date into number but when i convert date into number i see an other exception in oracle query – Pinchas K Oct 18 '12 at 12:55
-
What would the number mean? Like I said, you need an interval, not a date. Is the number a number of days? Months? Years? Seconds? – Alex Oct 18 '12 at 13:00
-
As several people have said, your question is meaningless. Yet you persistently refuse to explain what is you are trying to achieve. Voting to close. – APC Oct 18 '12 at 13:20
1 Answers
3
Adding two dates together would be meaningless but you can add an interval to a timestamp. For example, to add 1 year and 10 months to a timestamp:
SELECT SYSDATE + INTERVAL '1-10' YEAR TO MONTH FROM DUAL;
You can also add days to a DATE
column using simple arithmetics. For example, you can add 45 days to the current date using:
SELECT CURRENT_DATE + 45 FROM DUAL;
-
For example, SELECT SYSDATE + TO_NUMBER(1) FROM DUAL this works. It will give the result as Oct 19. But these 2 do not compile SELECT SYSDATE + SYSDATE FROM DUAL (has problem with the +) SELECT SYSDATE + TO_NUMBER(SYSDATE) FROM DUAL (has invalid number issue) – Pinchas K Oct 18 '12 at 13:03
-
-
-
-
-
3How Oct 18,2012 + Oct 19, 2012 makes Oct. 20, 2012 is beyond my understanding... what about Oct 1,2012 + Oct 19, 2012? – Alex Oct 18 '12 at 14:35