Results 1 to 9 of 9

Thread: Years Enrolled

  1. #1
    Join Date
    Jul 2012
    Posts
    14

    Unanswered: Years Enrolled

    I am trying to figure out the years someone is enrolled in school. I have their start date and need to figure out the difference between then and the current date. I am new to the world of SQL so I apologize for my lack of knowledge.

    I was playing around with DATEDIFF but have been unable to really figure it out.

    Thanks in advance for your time!

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >I was playing around with DATEDIFF but have been unable to really figure it out.

    are you lost, confused, or befuddled?
    DATEDIFF is a MS SQL Sever function
    DATEDIFF (Transact-SQL)

    while this forum is for Oracle RDBMS

    run the SQL below

    SELECT * FROM V$VERSION;

    COPY the results then PASTE all back here
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jul 2012
    Posts
    14
    Here you go and thanks!

    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    "CORE 11.1.0.6.0 Production"
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production

  4. #4
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    select trunc(months_between(enroll_date,sysdate)/12) from my_table;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  5. #5
    Join Date
    Jul 2012
    Posts
    14
    Thank you I will give it a try!

  6. #6
    Join Date
    Jul 2012
    Posts
    14
    It returned values but they don't seem to be correct. This is what I have:
    0
    -2
    0
    0
    -2

    This is what my enrollmentdate data is looking like:
    06-MAY-2012
    06-JAN-2010
    31-DEC-2011
    06-MAY-2012
    06-JAN-2010

    Thanks!

  7. #7
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    reverse the dates to get positive numbers

    select trunc(months_between(sysdate,enroll_date)/12) from my_table;

    You asked for years so a date within 2012 would be 0 years.
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  8. #8
    Join Date
    Jul 2012
    Posts
    14
    Gotcha and thanks again!

  9. #9
    Join Date
    Jul 2012
    Posts
    14
    It would like a charm!

Posting Permissions

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