Calculate age on the specific date

  • CRCforms
    Asked on September 21, 2015 at 6: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

    Jotform Thread 666759 Screenshot
  • Ben
    Replied on September 21, 2015 at 1: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: 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:

    Calculate age on the specific date Image 1 Screenshot 40

    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:

    Calculate age on the specific date Image 2 Screenshot 51

    Of course, to be able to use this, we must set the date field properly:

    Calculate age on the specific date Image 3 Screenshot 62

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

  • Kevin Support Team Lead
    Replied 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.

    Regards.