Equivalent function for DATEADD() in Oracle

后端 未结 4 1867
时光说笑
时光说笑 2020-12-03 07:07

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

相关标签:
4条回答
  • 2020-12-03 07:44

    Method1: ADD_MONTHS

    ADD_MONTHS(SYSDATE, -6)

    Method 2: Interval

    SYSDATE - interval '6' month

    Note: if you want to do the operations from start of the current month always, TRUNC(SYSDATE,'MONTH') would give that. And it expects a Date datatype as input.

    0 讨论(0)
  • 2020-12-03 07:47

    Not my answer :

    I wasn't too happy with the answers above and some additional searching yielded 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 helpful. From http://sqlbisam.blogspot.com/2014/01/add-date-interval-to-date-or-dateadd.html

    0 讨论(0)
  • 2020-12-03 07:52
    --ORACLE SQL EXAMPLE
    SELECT
    SYSDATE
    ,TO_DATE(SUBSTR(LAST_DAY(ADD_MONTHS(SYSDATE, -1)),1,10),'YYYY-MM-DD')
    FROM DUAL
    
    0 讨论(0)
  • 2020-12-03 07:58

    Equivalent will be

    ADD_MONTHS( SYSDATE, -6 )
    
    0 讨论(0)
提交回复
热议问题