I am trying to write a date of birth compair. here is how i have started out but I am not getting the results I want to see I am wanting to enter the text as

03/14/73 and compaire that to todays date and tell the user how old they are in only years.

This is as far as I can get with it and I will be totaly truthfull I did not write the hole thing this is the beginging of a class assinment and I cant find were on the net to get help. Sugestions. Please.

System.out.print("Enter the year you were born: ");
        	 usrYear = getYear(year);
        	 userYr = Integer.parseInt(usrYear);
        		 
	System.out.print("Enter the month you were born: ");
       		 usrMonth = getMonth();
       		 userMth = Integer.parseInt(usrMonth);

	 System.out.print("Enter the day you were born: ");
       		 usrDay = getDay(userMth);
       		 userDay = Integer.parseInt(usrDay);

	 System.out.println("Your birthday is on " + userMth + "/" + userDay + "/" + userYr);
       		 displayAge(userYr, year, userMth, month, userDay, day);
	 }
        		 
	 public static String getYear(int yr)throws Exception {		 
 		 int outYear=0;
 		 int year;
 		 year = yr;
 		 String usrYear = new String();
 		 String output = new String();
 		 usrYear = getString();

:?:

hi,

here is a simple program that gives you your age month and day...give the date of birth as an argument though...

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParseException;

public class Age {

  public Age(long birthday) {
    Calendar age = Calendar.getInstance(Locale.getDefault());
    age.setTimeInMillis(Math.abs(birthday-System.currentTimeMillis()));
    System.out.println("Your are "+(age.get(Calendar.YEAR)-1970)+" years, "+age.get(Calendar.MONTH)+" month, "+age.get(Calendar.DAY_OF_MONTH)+" days "+(System.currentTimeMillis()-birthday<0 ?"Not Born Yet" :"Old")+".");
  }

  public static void main(String[] args) {
    SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
    if (args.length==0) {
      System.out.println("Usage:\n java Age dd/mm/yyyy\nWhere:\n dd - date\n mm - month\n yyyy - year");
    } else {
      try {
        final Date birthday = dateFormatter.parse(args[0]);
        System.out.println("Your birthday is " + dateFormatter.format(birthday));
        final Age myAge = new Age(birthday.getTime());
      } catch (ParseException e) {
        System.out.println("Error parsing your birthday.");
        e.printStackTrace();
      }
    }
  }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.