Search code examples
sqloracledate-arithmeticoracle8i

Subtracting n Days from a date using SQL


I am quite a beginner when it comes to Oracle. I am having trouble figuring out how to do something similar to this :

SELECT ID, NAME, TO_CHAR(DATEBIRTH, 'DD/MM/YYYY HH24:MI:SS') 
FROM PEOPLE WHERE DATEBIRTH >= ANOTHERDATE - NDAY

To put it short, I want to select everyone who were born N days before a specific date and time but I am not quite sure that this is the way to do it nor that it would give me the results I expect.

PS: I am developping under oracle8i.


Solution

  • Your query looks correct to me. That's how you subtract days from dates in Oracle. This link holds some more insight for you, should you want to add months or years:

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1157035034361