+ Reply to Thread + Post New Thread
Results 1 to 3 of 3
  1. simona007's Avatar
    simona007 is offline Junior Member
    Join Date
    17 Nov 2008
    Posts
    11
    Say Thanks
    2
    Thanked 0 Times in 0 Posts

    DATEDIFF function in Oracle like SQL Server

    Hi guys, hope everyone is good

    Can someone tell me the equivalent for the SQL Server DATEDIFF function in Oracle

    For example, in Microsoft SQl server, I can do
    Code :
    SELECT DATEDIFF(dd, date_var , GETDATE())
    This gives the difference in number of days between date_var and GETDATE(). Now what's the equivalent in Oracle. If i do
    Code :
    select date_var-sysdate from temp
    , it gives me an error ORA-00932: inconsistent datatypes: expected NUMBER got INTERVAL, what am i missing here?

    Regards,
    Simona

  2.    Club-Oracle Complementary E-Books and Magazines
    Get your free Complementary Copy of Oracle Magazine

    You can also browse the Free Magazines and E-Books section to see the complete list of free magazines, e-books and Whitepapers.

  3. tyro's Avatar
    tyro is offline Forum Genius
    Join Date
    20 Aug 2008
    Location
    India
    Posts
    363
    Say Thanks
    0
    Thanked 17 Times in 17 Posts

    Re: DATEDIFF function in Oracle like SQL Server

    did u say "got interval", try this
    Code :
    select (SYSTIMESTAMP - date_var) from temp

  4. rajavu's Avatar
    rajavu is offline Forum Genius
    Join Date
    13 Oct 2008
    Location
    @ Bangalore , India
    Posts
    410
    Say Thanks
    0
    Thanked 16 Times in 15 Posts

    Re: DATEDIFF function in Oracle like SQL Server

    First all , you didn't mentioned about the data type of date_var.

    If it is non-date datatype , that needs to be converted to date while doing such operations.

    Code :
    SQL> SELECT SYSDATE - TO_DATE('20081205','YYYYMMDD') datediff FROM DUAL;

      DATEDIFF
    ----------
    80.4018519

    SQL> SELECT TRUNC(SYSDATE) - TO_DATE('20081205','YYYYMMDD') datediff FROM DUAL;

      DATEDIFF
    ----------
            80

    SQL>
    Last edited by rajavu; 02-23-2009 at 04:13 AM.

    Raj.

Similar Threads

  1. Replies: 5
    Last Post: 03-05-2010, 03:33 PM
  2. Connection Server : Launch Archiver for Content Server not working
    By noel in forum Oracle Fusion Middleware
    Replies: 1
    Last Post: 02-26-2009, 07:24 AM
  3. How to pass parameters to a pl/sql function from Oracle Discoverer Desktop?
    By Gabo86 in forum Oracle Developer Suite and Tools
    Replies: 3
    Last Post: 02-24-2009, 10:00 AM
  4. PL/SQL function to return more than one value
    By oracle_new in forum SQL PL/SQL
    Replies: 2
    Last Post: 01-28-2009, 12:46 PM
  5. Aggregate function in SQL Server
    By sowmyav in forum Other Databases
    Replies: 4
    Last Post: 01-16-2009, 07:12 AM

Tags for this Thread