JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.
We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.
Calculate age on the specific dateAsked by CRCforms on September 21, 2015 at 06:30 AM
I've worked out how to calculate age from Date of Birth but now I need to add an extra calculation that will automatically tell me what age I am on 31st August 2016 rather than today's date?
Your help or advice would be greatly appreciated! Thank you
The function is actually the same for both, the only difference is to have the DateTime field set up to current or the default time.
This is the form that I ended up with: http://form.jotformpro.com/form/52633567051959
What we need to do when calculating the current age, is to have 2 DateTime fields, one for the user to set the age, and another (I prefer hidden) for the current date, and we just make the math for it to take the birth date, from the current date.
Now we get some numbers, which we need to divide by 365. It does not matter that every 4 years there is a different set of numbers, this will still round them up closely for us.
Now, this is good as long as you are born in the month that will not go over the .5 as soon as you are born in a month such as December, you would get an extra year, so this is resolved by using floor() function.
This is how it looks when everything is added:
Now as you will see on the following screenshot, the same is applied on the second Form Calculation that will calculate the age on that specific date:
Of course, to be able to use this, we must set the date field properly:
Once this is all set - it works just as on the sample above :)
If you would like, you can grab the form to your own account, by cloning it as shown on this guide: How to Clone an Existing Form from a URL
Do let us know how it goes :)
how then can we
1. tell the user they are too old or young and
2. force the user to enter a valid date
Yes, you can do both things, just follow the steps provided by my collegue above and you will be able to tell the user he/she is too old or young and force to enter a valid date.
Let us know if you have questions, we will be glad to assist you.