I want to write a method to calculate the age from the birth date, is the logic correct and how to write it in android Java:
public int calculateAge(String b
This works Perfectly.....
public int getAge(int DOByear, int DOBmonth, int DOBday) {
int age;
final Calendar calenderToday = Calendar.getInstance();
int currentYear = calenderToday.get(Calendar.YEAR);
int currentMonth = 1 + calenderToday.get(Calendar.MONTH);
int todayDay = calenderToday.get(Calendar.DAY_OF_MONTH);
age = currentYear - DOByear;
if(DOBmonth > currentMonth) {
--age;
} else if(DOBmonth == currentMonth) {
if(DOBday > todayDay){
--age;
}
}
return age;
}