Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 531
MrMokari Avatar asked Sep 07 '11 15:09

MrMokari


1 Answers

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

like image 88
Lukas Eder Avatar answered Sep 22 '22 05:09

Lukas Eder