Calculate age on the specific date

  • Profile Image
    Asked 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

  • Profile Image
    Answered on September 21, 2015 at 01:10 PM

    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:

    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 :)

  • Profile Image
    Answered on November 24, 2015 at 06:47 PM

    how then can we

    1. tell the user they are too old or young and

    2. force the user to enter a valid date

  • Profile Image
    Answered on November 24, 2015 at 10:16 PM

    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.

    The age of the user will be in the You Have field,you can add a limit of age to submit the form, take a look into the form, clone it and make tests.

    Let us know if you have questions, we will be glad to assist you.