Populate Hidden Date Field With Current Year

  • DreamCalisthenics
    Asked on July 11, 2015 at 8:06 PM

    Hi,

    I am developing a form that calculates a person's age on new years eve of the current year. The EOY date field is only used for calculation and therefore will be hidden. Is there any way to dynamically set the year field for the date to the current year so that the form doesn't have to be updated each year whilst maintaining static values for day and month? (31 December)

     

    Thanks

    Ben

  • Mike_G JotForm Support
    Replied on July 12, 2015 at 2:32 AM

    I'm not sure exactly how you would like your form be used. But you can use the Date field and set the Default Date to the Current Date. By doing that the Date field changes every day. The Default date is equivalent to the date on your device or your computer, where the form is opened. 

    Populate Hidden Date Field With Current Year Image 1 Screenshot 30

    Eventually, the date field will be 12/31/CurrentYearHere

    You'll just have to subtract the Person's Birthday from the Current Date. (use another Date field to get the Person's Birthday) Divide the difference by 365.25 days to get Age. Also, get the Floor value of the Age so that its value will be rounded to the nearest integer. Use this guide: Form-Calculation-Math-Function-Reference

    Populate Hidden Date Field With Current Year Image 2 Screenshot 41

    Here's the form I have used for my example: http://form.jotformpro.com/form/51921351271953

    Please feel free to clone it for your reference. 

    I hope this helps. Let us know if you need further assistance. Thank you. 

  • Mike_G JotForm Support
    Replied on July 12, 2015 at 2:44 AM

    I would like to apologize. I have mistakenly used the Math Function Floor(). You can remove that and instead use this workaround to remove the decimal places on the Person's Age Value. 

    Populate Hidden Date Field With Current Year Image 1 Screenshot 20

    Thank you. 

  • DreamCalisthenics
    Replied on July 12, 2015 at 4:02 AM

    I'm looking to have a static defined date that is 31 December YYYY where YYYY is dynamically populated. Otherwise I have to update the form annually to match the current year. I'm not sure if you can define it using something like 31/12/{dateField:year} or using #year_1?

    Its not that huge if I have to manually update it but it makes the form robust.

  • Mike_G JotForm Support
    Replied on July 12, 2015 at 4:33 AM

    Unfortunately, this: {dateField:year} is not working with conditions. But I was able to think of a way to get the current year only and place it on a field. However, this, of course, still involves a Date field with Default Date set to Current Date.

    Populate Hidden Date Field With Current Year Image 1 Screenshot 20

    Since, I think, you only need to get the current year and the year of the Person's birthday to get the age. I have extracted both years from their corresponding Date field and get the difference. 

    Try playing with this form by cloning it. 

    http://form.jotformpro.com/form/51918717550965

    If you change the Current Date Field's Year, the year on the New Year's Eve field will also change.

    Meaning, every year the Date on the New Year's Eve field will change automatically. 

    Let us know if this works for you. Thank you. 

  • DreamCalisthenics
    Replied on July 15, 2015 at 10:46 PM

    Since, I think, you only need to get the current year and the year of the Person's birthday to get the age. I have extracted both years from their corresponding Date field and get the difference.

    I'll have a look and see if it meets my needs. I'm not sure it will as I need to calculate their age on New Years eve based upon their DOB.

    eg: Players registering for 15 years and under can be > 15yo but not 16 as of the end of the current year. (31 December)

    Thanks.

  • DreamCalisthenics
    Replied on July 15, 2015 at 11:01 PM

    What is the difference using 0 decimal places instead of the floor() function?