First example: birthdate :10-01-1991(ddmmyyyy)
CurrentDate :10-01-2017
if above is the condition then I want to print 26 as current age.
Second example: birthdate :25-07-1991(ddmmyyyy)
CurrentDate :10-01-2017
if above is the condition then I want to print 25 as current age.
please help me ....!!!!!!
Below is the code that i have tried.
private int calculateage(Integer day1, Integer month1, Integer year1)
{
Calendar birthCal = new GregorianCalendar(1991, 01, 10);
Calendar nowCal = new GregorianCalendar();
age = nowCal.get(Calendar.YEAR) - birthCal.get(Calendar.YEAR);
boolean isMonthGreater = birthCal.get(Calendar.MONTH) >= nowCal
.get(Calendar.MONTH);
boolean isMonthSameButDayGreater = birthCal.get(Calendar.MONTH) >= nowCal.get(Calendar.MONTH)
&& birthCal.get(Calendar.DAY_OF_MONTH) >= nowCal
.get(Calendar.DAY_OF_MONTH);
if (age < 18) {
Age = age;
}
else if (isMonthGreater || isMonthSameButDayGreater) {
Age = age - 1;
}
return Age;
}