Home > Net >  SYSDATE - 2YEARS
SYSDATE - 2YEARS

Time:01-19

I have this in a query

from STG_WLT_FN_GF where date_yyyymmdd >= 20191101 )

And I want, have date -2 years sysdate, it's possible ?

Vanessa

CodePudding user response:

Another option would be using the add_months function.

add_months(sysdate, 12 * -2) 

Interval is known to have problems with certain dates (f.e. 31.03.) and it lacks the proper handling of leap years. You would get an exception if executing the above answers code on 29.02.:

select to_date('29.02.2024') - interval '2' year from dual;

Where as following works:

select add_months(to_date('29.02.2024'), 12 * -2) from dual;

CodePudding user response:

You can use an interval expression:

SYSDATE - INTERVAL '2' YEAR
  •  Tags:  
  • Related