How to calculate correct age base on the current date using the form

  • Benflips
    Asked on July 20, 2016 at 8:59 PM
    Someone gave me this similar workaround a while ago, and I have just played with the cloned form I made, but it doesn't seem to give an accurate result - example, I put in my date of birth 1 Aug 1978 and it said I was 39.

    Now, I WILL be 39 this year, but I am not right now...can the code be tweaked to take account of the days that have elapsed compared with your actual birthday to make sure the result is 100% accurate?

    There is no point using this (otherwise great) code, if the result is off my a year because of the issue as described above.

  • jonathan
    Replied on July 20, 2016 at 10:53 PM

    You must be referring to the Calculate Age template form 

    link: https://www.jotform.com/form-templates/calculate-age

    How to calculate correct age base on the current date using the form Image 1 Screenshot 20

     

    I think the Dates Difference widget has the more accurate calculation.

    I will check how it can be applied on the age calculation form also. I'll get back to this as soon as I have update.

    Thanks.

  • jonathan
    Replied on July 20, 2016 at 10:57 PM

    I also found a solution that work on another user about the same scenario.

    You can review the thread here

  • jonathan
    Replied on July 20, 2016 at 11:12 PM

    Please test this form https://form.jotform.com/62018374848967

    How to calculate correct age base on the current date using the form Image 1 Screenshot 20

    You can also clone the form so you can review it on your Form Builder.

    Let us know if you need further assistance.

  • Benflips
    Replied on July 21, 2016 at 6:20 PM

    How do I clone again?

    I have tested, this does work great.

    Can you just tell me how to insert this into my existing form, using the existing DOB field I have currently on that form - I assume it's a number of hidden fields and calculation rules like earlier suggestions?

  • jonathan
    Replied on July 21, 2016 at 6:43 PM

    Please refer to our user guide on how to clone a form.

    User guide: How-to-clone-an-existing-form-from-a-URL

    This is my test form URL https://form.jotform.com/62018374848967 

    -- 

    I suggest you clone the form so that you can better review it on your Form Builder. And you will be able to see also the hidden fields and calculation formula once you have the cloned form.

    Below are also the steps I did to create the form.

    How to calculate correct age base on the current date using the form Image 1 Screenshot 30

     

    The "Your Age" calculation have this formula: (you can see it also on the form once you cloned it)

    How to calculate correct age base on the current date using the form Image 2 Screenshot 41

     

    As you can see I used the floor() function and divide the number of Days by 365.25.

    Just add the necessary fields on your form and use the same formula for the Calculation fields.

    Let us know how we can be of further assistance.

  • Benflips
    Replied on July 21, 2016 at 9:45 PM
    Spectacular. It worked! Thanks.
    Now, can I have some help reducing the Age input (434) to the width of its
    label, and hopefully still having height and weight on the same line.
    Also, can you give me code to change the input field's appearance to look
    'greyed out' or some other appearance to differentiate it from an active
    field requiring an input. I have set the field to read-only, but that
    hasn't changed the field's appearance
    https://www.jotform.com//?formID=43420990799871

    *Regards,*
    *Dr. Ben Phillips*
    Chiropractor
    B.App.Sc.(Comp.Med.)(Chiro) M.Clin.Chiro.(RMIT)
    ...
  • jonathan
    Replied on July 21, 2016 at 10:58 PM

    I created a separate thread for the next question here https://www.jotform.com/answers/888322

    We will attend to it shortly.

  • OBrandman
    Replied on May 17, 2017 at 8:24 AM

    Hi, this works, although when the date of birth field is blank I am getting a number appear in the age field, please advise
  • Welvin Support Team Lead
    Replied on May 17, 2017 at 8:54 AM

    @OBrandman: I have created a new thread for your inquiry. Link here https://www.jotform.com/answers/1146960