title: Oracle PL/SQL, How to calculate age from date birth using simple substitution variable and months_between
body: <p>I am working on a simple PL/SQL block that asks the user their Date Of Birth and calculates their age.  I've used the months_between divided by 12 conversion but I am having trouble with the date conversion and date input from the user for the substitution variable. Please ignore the v_birthday_year as that is another part of the code I have to integrate in later. </p>
  
  <p>I'm not sure the format that the user has to type in, ie 05-07-1980, or 06 Mar 1978 that would be acceptable, and how to calculate their age from what they put in.  </p>
  
  <p><strong>My desired program is to write a PL/SQL program to accept the user's birthdate in this format DD-MON-YYYY, and calculates the Age in with 1 Decimal place.  So I need it calculated out to one decimal place too.</strong></p>
  
  <p>Here is what I have, but I'm not sure what format to type in the DOB at the substitution variable input and the actual calculation with one decimal place.  I'm just trying to see where I'm going wrong and how to correct it.</p>
  
  <pre><code>SET SERVEROUTPUT ON
  DECLARE
    --v_birthday_year         NUMBER(4)    := &amp;v_birthday_year;
    v_dob                   DATE      := &amp;v_dob 
    v_your_age              NUMBER(3, 1);
  BEGIN
    v_your_age := TRUNC(MONTHS_BETWEEN(SYSDATE, v_dob))/12;  
    DBMS_OUTPUT.PUT_LINE ('Your age is ' || v_your_age);
  END;
  /
  </code></pre>