Results 1 to 3 of 3

Thread: count years

  1. #1
    Join Date
    Apr 2004
    Posts
    6

    Unanswered: count years

    hi i want to know how to count years from dates...
    so todays_date minus 14-Feb-1999 = 5 years....
    right now im using
    SELECT P.LAST_NAME as "Last Name",
    ((SYSDATE - P.DATE_LAST_UPDATED)/365) as "years"
    FROM PATIENT P;

    is there any way thats simpler than divide by 365?
    thank you so much
    Last edited by Yuu; 04-18-04 at 02:15.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    simpler? sure, several ways

    the easiest is

    select year(p.date_last_updated) - year(sysdate)

    check your database for something like a DATEDIFF function too
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Originally posted by r937
    select year(p.date_last_updated) - year(sysdate)
    While this is syntactically simpler, you can still run into problems if you don't consider whether the SYSDATE day of the year is before/after the day of the p.date_last_updated day of the year.

    -PatP

Posting Permissions

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