title: Calculate age in Years, Months, Days, Hours, Minutes, and Seconds
body: <p>I need to take a birthday entered by the user (preferably in <code>dd/mm//yyyy</code> format) and find their age, based on todays date. Could someone explain to me the process I should go through to find this? I need to print it out in the format:</p>
  
  <blockquote>
    <p>"You are 19 years, 4 months, 12 days, 8 hours, 44 minutes, and 39 seconds old."</p>
  </blockquote>
  
  <p>I'm just a little confused on how I would subtract a date from another date, and how I would reference each part (years, months, days, hours, etc) separately.</p>
  
  <p>The code I have at the moment for reference:</p>
  
  <pre><code>import java.sql.Date;
  import java.text.DateFormat;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Scanner;
  
  public class Driver {
  
      public Driver(){}
  
      public static void main( String[] args){
      Driver menu = new Driver();
      MenuOptions option;
      do{
          menu.displayMenu();
          option = menu.getResponse();
          menu.runOption(option);
      }while(option != MenuOptions.Quit);  
      }
  
      private enum MenuOptions{
      AgeCalc("Calculate your age"),
          AnniversaryCalc("Calculate time until specified date"),
          AgeDifference("Find the time between two specified dates"),
          Quit("Exit the program");
  
      private String value;
  
      private MenuOptions(String value){
          this.value = value;
      }
  
      public String toString(){
          return value;
      }
      }
  
      public void displayMenu(){
      for(MenuOptions option : MenuOptions.values()){
          System.out.printf("%5d: %s\n", option.ordinal()+1, option);
      }
      }
  
      public MenuOptions getResponse(){
      int value = -1;
      Scanner input = new Scanner(System.in);
  
      do{
          System.out.println("&gt; ");
          String response = input.nextLine();
  
          if(response.matches("\\d+")){
          value = Integer.parseInt(response);
          if(value &lt; 1 || value &gt; MenuOptions.values().length){
              value = -1;
              System.out.println("Unknown response, please enter a number between 1 and " +MenuOptions .values().length);
          }
          }
  
      }while(value &lt;=0);
  
      return MenuOptions.values()[value-1];
      }
  
      public void runOption(MenuOptions option){
      Scanner in = new Scanner(System.in);
  
      switch(option){
      case AgeCalc:
          System.out.println("Please enter your birthday mm/DD/yyyy).");
          System.out.println("&gt;");
  
          DateFormat df = new SimpleDateFormat("mm/DD/yyyy");
  
          try
          {
              java.util.Date birthday = df.parse(in.nextLine());           
              System.out.println("Today = " + df.format(birthday));
          } catch (ParseException e)
          {
              e.printStackTrace();
          }
          Calendar today = Calendar.getInstance();
          java.util.Date today = df.format();
  
          DateFormat simple = new SimpleDateFormat("dd/MM/yyyy");
          String birthdate = simple.format(in.nextLine());
          Date.parse(birthdate);
  
          System.out.println(birthdate.toString());
          break;
      case AnniversaryCalc:
          System.out.printf("PI: %.20f\n", Math.PI);
          break;
      case AgeDifference:
          for(int p=0; p &lt;= 32; p++){
          System.out.println("2^" +p+" = " +Math.pow(2,p));
          }
      }
      }
  }
  </code></pre>