Hello Every one..i want create age calculate in app inventor 2 how to create???

467 views
Skip to first unread message

Ozal Muhamad

unread,
Jan 1, 2016, 11:41:01 AM1/1/16
to MIT App Inventor Forum
115580.png

Abraham Getzler

unread,
Jan 1, 2016, 3:22:58 PM1/1/16
to MIT App Inventor Forum
Use the Clock component in the Designer's Sensors drawer.

It has many important blocks, including
Now(),
Milliseconds from 1970,
and conversion and formatting and duration functions.
ABG

Ozal Muhamad

unread,
Jan 2, 2016, 4:26:14 AM1/2/16
to MIT App Inventor Forum
Plz Do You Have Tut??
How To Make It??
iam A New User on MIT App Inventor

Ghica

unread,
Jan 2, 2016, 5:28:32 PM1/2/16
to MIT App Inventor Forum
This is not as easy as it sounds. You can calculate a duration expressed as a number of milliseconds, but to calculate the number of your in it is not trivial, because there are leap years and such. So, this is something that would work: 
Calculate the duration between now and birth date. That will be a negative number.
Kepp adding a year using Clock1.AddYears, until the duration becomes positive.
Subtract 1 and you have your age.

If you try to calculate an age > 100 you will get 99 and when you take a date in the future as birth date, you will get -1, if you specify an invalid date, you will get an error message. For your enjoyment, I added an .aia to try out.
Cheers, Ghica.
agecalc.aia

Marine

unread,
Jan 3, 2016, 12:21:46 AM1/3/16
to mitappinv...@googlegroups.com

Ozal Muhamad

unread,
Jan 3, 2016, 12:34:17 PM1/3/16
to MIT App Inventor Forum
Thank you bro :)
Reply all
Reply to author
Forward
0 new messages