DATEDIFF function in Oracle like SQL Server

in Oracle Database; Hi guys, hope everyone is good Can someone tell me the equivalent for the SQL Server DATEDIFF function in Oracle ...

+ Post Reply + Post New Topic
Results 1 to 3 of 3
  1. #1
    simona007's Avatar
    simona007 is offline Junior Member simona007 is on a distinguished road
    Join Date
    17 Nov 2008
    Posts
    12
    Document Uploads
    0

    Helpful? Yes No

    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. #2
    tyro's Avatar
    tyro is offline Forum Genius tyro is on a distinguished road
    Join Date
    20 Aug 2008
    Location
    India
    Posts
    362
    Document Uploads
    0

    Helpful? Yes No

    Re: DATEDIFF function in Oracle like SQL Server

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

  4. #3
    rajavu's Avatar
    rajavu is offline Forum Genius rajavu is on a distinguished road
    Join Date
    13 Oct 2008
    Location
    @ Bangalore , India
    Posts
    482
    Document Uploads
    0

    Helpful? Yes No

    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 03:13 AM.

    Raj.

Similar Threads

  1. Replies: 1
    Last Post: 07-07-2010, 04:16 PM
  2. Inline Function vs Function
    By learnerSaumya in forum SQL PL/SQL
    Replies: 5
    Last Post: 04-29-2010, 06:48 PM
  3. Replies: 3
    Last Post: 05-15-2009, 11:58 AM
  4. Oracle 9i SQL DECODE Function Limitation
    By ygsunilkumar in forum SQL PL/SQL
    Replies: 6
    Last Post: 05-11-2009, 06:18 AM
  5. Aggregate function in SQL Server
    By sowmyav in forum Other Databases
    Replies: 4
    Last Post: 01-16-2009, 06:12 AM