Build an Age Calculator App Using MIT App Inventor

We are going to learn how to make an age calculator in MIT App Inventor. It is a really easy project to make and understand. 

MIT AI has something called a DatePicker which we will be using in this app. 

First, we add in a Vertical Arrangement layout from Layout Palette. Set its Height and Width to FillParent, and AlignVertical and AlignHorizontal to Center. 

image 99

Choose 2 DatePickers from User Interface Palette. We need the user to choose their birth date and the current date to calculate their age. So we rename the first DatePicker to “BirthDate” and the second to “CurrentDate”. Change their texts to the same. Set their Height to 10 percent and Width to 30 percent. 

image 100
image 101
image 102

Now we need to display these dates. We pick 2 Labels to do that. Label1 will display the Birthdate and Label2 will show the Currentdate. Rename them accordingly and keep their texts blank. 

image 103

Now we need a Calculate button so we put in a Button from User Interface, rename and change its text to “Calculate”. Set its height and width to the same dimensions as the DatePickers.  

image 104
image 115

We add one more Label to display the results. Rename it and keep text blank. 

image 114

We are done with the Design. We move to coding Blocks. 

Since we want the labels to display the dates, we use “when DatePicker.AfterDateSet” from the DatePicker blocks for both DatePickers. 

image 106

For birth date, we join a “set Birth_Display.Text to” block from BirthDate blocks. Also put in a “join” block from Text since we want to display multiple texts together in one Label. There should be 5 empty spaces in the “join” block. 

image 111

For alternate empty spaces we put in “BirthDate.Day”, “BirthDate.Month” and “BirthDate.Year” blocks from BirthDate blocks. 

image 107
image 108

In the rest of the empty spaces, we join the empty text blocks and fill it with “-” hyphen symbol. 

image 112

This will display the BirthDate in the format of “DD-MM-YYYY”.  

Similarly, we code the CurrentDate block too. 

image 117

Now all thats left is to code the Calculate Button. 

For that, we choose the “when Calculate.Click” block and add the “set Result.Text to” block from Result label. 

image 105

Now our logic for calculating the age is subtracting the birthdate from the currentdate. And we want the result to have the year and month. So we add a “join” block. And put in 3 empty spaces. 

image 109

For the first and third empty spaces, we put in subtract blocks from Math. And the second empty space should be empty text block with hyphen “-”. 

image 110

Now for the first empty space in the first join space, we put in “CurrentDate.Month” and “BirthDate.Month” for the second empty space. 

image 113

Same for the second subtract block except we put in “CurrentDate.Year” and “BirthDate.Year”. 

image 116

This will display the result in our Result label. And voila! We have our Age Calculator app. 

This Post Has 6 Comments

  1. binance

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

    1. makersmuse

      Thank you for your interest! Please feel free to reach out to us at hello@makersmuse.in, and we’d be happy to clarify any details for you.

  2. binance registrering

    Your point of view caught my eye and was very interesting. Thanks. I have a question for you.

    1. makersmuse

      Thanks for sharing your perspective—it really got me thinking! I’d love to ask you something further. Could you email me at hello@makersmuse.in

Leave a Reply

Coding For kids

Coding Courses for Kids Online

Our courses which are tailored for grades 1 to 12, and our hands-on curriculum seamlessly integrates, preparing students for challenges and inspiring the next generation.

STEM Labs

STEM LAB for Schools

Looking for a cutting-edge makerspace that goes beyond traditional education? Partner with Makers’ Muse to unlock innovation and transformative learning for your students.

Coding Toys

STEM LAB for Schools

Discover a revolutionary coding journey for students with our cutting-edge educational toys. Partner with us to unlock innovative learning experiences that transcend traditional education.

Do you have questions regarding our STEM program?

Send Us A Message