title: Calculating age from DOB extracted from database
body: <p>I have this code which I am using to calculate age from DOB.But I am not sure whether it is working properly or not as when I am calling this function from another file, I am not able to see any output.</p>
  
  <pre><code>public ArrayList&lt;Integer&gt; getEmployeeAge() {
          // TODO Auto-generated method stub
  
  
          ArrayList&lt;Integer&gt; employeeage = new ArrayList&lt;Integer&gt;();
          ResultSet rs = null;
  
          try {
              LibraryConnection lc = new LibraryConnection(library, dbConnection);
  
  
              rs = lc.executeQuery("GetEmployeeAge", null);
  
  
              while(rs.next()){   
  /*              QuartReport qcd = new QuartReport();
  
                  qcd.setYear(rs.getInt(1));
                  qcd.setQuarter(rs.getInt(2));
                  qcd.setCount(rs.getInt(3));
  */
  
                  String dob = rs.getString(1);
  
                  int yearDOB = Integer.parseInt(dob.substring(6, 10));
                  int monthDOB = Integer.parseInt(dob.substring(3, 5));
                  int dayDOB = Integer.parseInt(dob.substring(0, 2));
  
                  //CALCULATE THE CURRENT YEAR, MONTH AND DAY
                  //INTO SEPERATE VARIABLES
                  DateFormat dateFormat = new SimpleDateFormat("yyyy");
                  java.util.Date date = new java.util.Date();
                  int thisYear = Integer.parseInt(dateFormat.format(date));
  
                  dateFormat = new SimpleDateFormat("MM");
                  date = new java.util.Date();
                  int thisMonth = Integer.parseInt(dateFormat.format(date));
  
                  dateFormat = new SimpleDateFormat("dd");
                  date = new java.util.Date();
                  int thisDay = Integer.parseInt(dateFormat.format(date));
  
                  //CREATE AN AGE VARIABLE TO HOLD THE CALCULATED AGE
                  //TO START WILL – SET THE AGE EQUEL TO THE CURRENT YEAR MINUS THE YEAR
                  //OF THE DOB
                  int age = thisYear - yearDOB;
                  //IF THE CURRENT MONTH IS LESS THAN THE DOB MONTH
                  //THEN REDUCE THE DOB BY 1 AS THEY HAVE NOT HAD THEIR
                  //BIRTHDAY YET THIS YEAR
                  if(thisMonth &lt; monthDOB){
                  age = age -1;
                  }
  
                  //IF THE MONTH IN THE DOB IS EQUEL TO THE CURRENT MONTH
                  //THEN CHECK THE DAY TO FIND OUT IF THEY HAVE HAD THEIR
                  //BIRTHDAY YET. IF THE CURRENT DAY IS LESS THAN THE DAY OF THE DOB
                  //THEN REDUCE THE DOB BY 1 AS THEY HAVE NOT HAD THEIR
                  //BIRTHDAY YET THIS YEAR
                  if(thisMonth == monthDOB &amp;&amp; thisDay &lt; dayDOB){
                  age = age -1;
                  }
  
                  employeeage.add(age);
              }
  
              return employeeage;
          }catch (SQLException e) {
              e.printStackTrace();
          }catch (Exception e) {
              logger.error(e);
              e.printStackTrace();
          }finally {
              SqlUtils.close(rs);
          }
  
  
          return null;
      }
  </code></pre>
  
  <p>The xml query that I am executing is:</p>
  
  <pre><code>&lt;s:query name="GetEmployeeAge" xmlns:s="http://www.slamb.org/axamol/sql-library/statement"&gt;
  &lt;s:sql databases="mysql"&gt;
  SELECT DOB(`Date Of Birth`) 
  FROM `Employee` LEFT JOIN Employee-Detail ON `Employee.MRN` = `Employee-Detail.MRN`
  GROUP BY DOB(`Date Of Birth`)
  ORDER BY DOB(`Date Of Birth`) ASC
  &lt;/s:sql&gt;
  &lt;/s:query&gt;
  </code></pre>
  
  <p>Can anyone help me in pointing what might be the reason for this?</p>
  
  <p><strong>UPDATE1:</strong> The SQL query is working correctly.I executed it on MySQL workbench and it is returning the result in this format <code>YYYY-MM-DD 00:00:00</code> </p>
  
  <p><strong>UPDATE2:</strong> I am using the result of this to generate a graph whose details are present at <a href="https://stackoverflow.com/questions/23093641/generating-histogram-through-java-and-primefaces">Generating Histogram through Java and PrimeFaces</a></p>