Oracle SYSDATE minus INTERVAL - Subtracting Time Units

Oracle's SYSDATE function, combined with the INTERVAL keyword, provides a convenient way to manipulate dates and times.

Operations with SYSDATE on Oracle

Here are examples of subtracting different time units from the current date and time.

Subtracting Months

To subtract six months from the current date:

SELECT SYSDATE - INTERVAL '6' MONTH AS "Six Months Ago" FROM DUAL;

Subtracting Days

To subtract 10 days from the current date:

SELECT SYSDATE - INTERVAL '10' DAY AS "Ten Days Ago" FROM DUAL;

Subtracting Hours

To subtract 5 hours:

SELECT SYSDATE - INTERVAL '5' HOUR AS "Five Hours Ago" FROM DUAL;

Subtracting Minutes

To subtract 15 minutes:

SELECT SYSDATE - INTERVAL '15' MINUTE AS "Fifteen Minutes Ago" FROM DUAL;

Conclusion

These examples show how to use the INTERVAL keyword with SYSDATE to perform common date and time operations in Oracle. This approach is both intuitive and precise, allowing for clear and readable SQL queries when adjusting timestamps.

Love Discord?