View Single Post
Old 08-08-08, 05:04 PM   #2 (permalink)
poolasumithkumar
Junior Member
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1 poolasumithkumar is on a distinguished road
logic for date difference in years

this is the new method , instead of Date pass Calendar object which need to be calculate


- public static int calcAge(Calendar dob) {
int age = 0;
Calendar curDate = Calendar.getInstance();
Calendar tmpDate = Calendar.getInstance();
tmpDate.setTime(dob.getTime());
tmpDate.set(Calendar.YEAR,curDate.get(Calendar.YEAR));
if (dob.before(curDate)) {
age = curDate.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
if (tmpDate.after(curDate)) {
age--;
}
}
return age;
}
poolasumithkumar is offline   Reply With Quote