Click here to Skip to main content
15,067,539 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Everyone,

I want to Calculate age of a person, as soon as he selects the datepicker

I'm a self learning android developing Banker and don't have a programming knowledge. Kindly help me out in a easiest solution.

What I have tried:

Googled and tried to use many codes and ended up confusing myself.
Updated 14-Nov-16 9:19am
Richard MacCutchan 7-Nov-16 7:48am
Calculating age is just the same in Java as in your native language. You take the current date and subtract the Date of Birth. If you have a problem with your code then please edit the question and show us what you have tried, and what is wrong.

It is not difficult. Your inputs are current date (say now) and the user date of birth (say bd).
The user age (how many years the user old) is (pseudocode)
age = now.year - bd.year;

if (now.day_of_year < bd.day_of_year)
  age = age - 1;
How would you do it with pencil and paper? Until you get that far, messing with code is a moot point.
Googled and tried to use many codes and ended up confusing myself.
Advice to beginner, don't try to learn by searching 'random' code.
You need to find some tutorials and follow them to learn something.
There is no magic easy way to learn programming.
Advice: Put your project on hold while you follow the tutorials.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900