Skip to content
Advertisement

How to subtract years from sysdate

What would be the expression to check if someone’s 20 years or over without hard-coding the date?

In the SQL

 SELECT student_fname 
 FROM students
 WHERE dob<'05-MAR-1995';

I was thinking about using SYSDATE but then I don’t know the syntax to subtract 20 years.

Advertisement

Answer

WHERE dob < add_months( trunc(sysdate), -12*20 );

would work assuming that you want to ignore the time component of sysdate.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement