3 Replies Latest reply: Dec 3, 2012 3:55 AM by BluShadow RSS

    Datediff in SQL

    977438
      SELECT DATEDIFF(day,'2008-06-05','2008-08-05') AS DiffDate from dual is not working in SQL

      ERROR :
      ORA-00904: "DATEDIFF": invalid identifier
      00904. 00000 - "%s: invalid identifier"
      *Cause:   
      *Action:
      Error at Line: 1 Column: 7

      Regards
      Santhosh M
        • 1. Re: Datediff in SQL
          977438
          Issues
          • 2. Re: Datediff in SQL
            sb92075
            user3535401 wrote:
            SELECT DATEDIFF(day,'2008-06-05','2008-08-05') AS DiffDate from dual is not working in SQL

            ERROR :
            ORA-00904: "DATEDIFF": invalid identifier
            00904. 00000 - "%s: invalid identifier"
            *Cause:   
            *Action:
            Error at Line: 1 Column: 7

            Regards
            Santhosh M
            while DATEDIFF is a valid function on MS SQL Server; it does not exist in Oracle RDBMS.
            • 3. Re: Datediff in SQL
              BluShadow
              Oracle equivalents e.g.
              SQL> ed
              Wrote file afiedt.buf
              
                1  with t as (select date '2008-06-05' as dt_from, date '2008-08-05' as dt_to from dual)
                2  --
                3  -- end of test data
                4  --
                5  select dt_to - dt_from as days_between
                6        ,months_between(dt_to, dt_from) as mnth_between
                7* from t
              SQL> /
              
              DAYS_BETWEEN MNTH_BETWEEN
              ------------ ------------
                        61            2
              
              SQL>