Equivalent function for DATEADD () in Oracle

I need to get a date that is 6 months from the system date in Oracle.
And I need to get it by running an open query from SQL. The function DATEADD(MONTH,-6, GETDATE())serves a purpose in SQL.

Does a function DATEADD(MONTH,-6, GETDATE())in SQL have a function equivalentin Oracle?

+13
source share
3 answers

Method1: ADD_MONTHS

ADD_MONTHS(SYSDATE, -6)

Method 2: Interval

SYSDATE - interval '6' month

Note:  if you want to always perform operations from the beginning of the current month, TRUNC(SYSDATE,'MONTH')this will give. And it expects input of type Dateas input.

+23
source

Equivalent to be

ADD_MONTHS( SYSDATE, -6 )
+4

Not my answer :

I was not too happy with the answers above, and some additional searches gave this:

SELECT SYSDATE AS current_date,

       SYSDATE + 1 AS plus_1_day,

       SYSDATE + 1/24 AS plus_1_hours,

       SYSDATE + 1/24/60 AS plus_1_minutes,

       SYSDATE + 1/24/60/60 AS plus_1_seconds

FROM   dual;

which I found very useful. From http://sqlbisam.blogspot.com/2014/01/add-date-interval-to-date-or-dateadd.html

0
source

Source: https://habr.com/ru/post/1771263/


All Articles