DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: SQL Function

  1. #1
    Join Date
    Feb 2006
    Posts
    162

    SQL Function

    Is there any function in SQL to find difference between two dates in days?

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    minus one date from the other

  3. #3
    Join Date
    Sep 2005
    Location
    Delhi
    Posts
    78
    try datediff(date1,date2)
    ~KD.DBA~

  4. #4
    Join Date
    Apr 2006
    Posts
    377
    Quote Originally Posted by dhar_kiran
    try datediff(date1,date2)
    That's a Sybase thing, isn't it?

  5. #5
    Join Date
    Feb 2006
    Posts
    162
    Hi Dave,

    Can you give the syntax for the same?

  6. #6
    Join Date
    Feb 2006
    Posts
    162
    because i tried like this

    SQL> select 20/03/2006 - 21/03/2006 from dual;

    20/03/2006-21/03/2006
    ---------------------
    -.00016617

    This output look somewhat strange,thats why i asked syntax.

  7. #7
    Join Date
    Nov 2005
    Location
    Indianapolis
    Posts
    24

    Subtract dates

    That's because you didn't subtract 2 dates, you just subtracted 2 numbers. You need to use date formats:

    Code:
      1* select to_date('25-MAY-2006','DD-MON-YYYY') - to_date('23-MAY-2006','DD-MON-YYYY') from dual
    SQL> /
    
    TO_DATE('25-MAY-2006','DD-MON-YYYY')-TO_DATE('23-MAY-2006','DD-MON-YYYY')
    -------------------------------------------------------------------------
                                                                            2

  8. #8
    Join Date
    Feb 2006
    Posts
    162
    Thanks wdfloyd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width