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

Thread: how to find no of years

  1. #1
    Join Date
    Jan 2003
    Posts
    141

    how to find no of years

    Hi,
    How to find the no. of years between two dates. Is there any function like date between to find the no of years between two dates

  2. #2
    Join Date
    May 2002
    Posts
    2,645
    Search for "date arithmetic" in the SQL Reference Guide.

  3. #3
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    PHP Code:
     1  select sysdatesysdate-2000,
     
    2  to_number(to_char(sysdate,'YYYY')) - 
         
    to_number(to_char((sysdate-2000),'YYYY')) diff
     3
    from dual
    SQL
    > /

    SYSDATE              SYSDATE-2000               DIFF
    -------------------- -------------------- ----------
    15-dec-2004 13:11:23 25-jun-1999 13:11:23          5 
    Is this you are looking for?

    Tamil

  4. #4
    Join Date
    Aug 2002
    Location
    Colorado Springs
    Posts
    5,253
    How about ...
    Code:
    Floor(Months_Between(date1,date2)/12)
    David Aldridge,
    "The Oracle Sponge"

    Senior Manager, Business Intelligence Development
    XM Satellite Radio
    Washington, DC

    Oracle ACE

  5. #5
    Join Date
    May 2002
    Posts
    2,645
    Or (something easy to experiment with in scott/tiger):

    select (sysdate-hiredate)/365 from emp;

    This can be further refined to return the whole number (5.234 years counts as 5), or the integer part plus one (5.234 years counts as 6).

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