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 birthday){
// consider that birthday format is ddmmyyyy;
String today = SystemDate(ddmmyyyy);
int bDay = birthday(1,2).toInteger;
int bMonth = birthday(3,4).toInteger;
int bYear = birhtday(5,8).toInteger;
int tDay = today(1,2).toInteger;
int tMonth = today(3,4).toInteger;
int tYear = today(5,8).toInteger;
if (tMonth == bMonth){
if (tday>= bDay){
age = tYear - bYear;
else
age = tYear - bYear - 1;}
else
if (tMonth > bMonth) {
age = tYear - bYear;
else
age = tYear - bYear - 1;}
}
return age;
}
See Question&Answers more detail:os