How do I Create a dynamic date?

  • DreamCalisthenics
    Asked on November 21, 2015 at 1:23 AM

    Hi,

    I'm not sure if this is possible currently so this is why I ask. :)

    I need to create a date for calculations based upon a specific roll over date in the future for the current year. Currently I have to statically define the future date that becomes invalid once the date passes. Is there any possibility that the date field can be augmented to allow the date's year, month or day to be defined dynamically?

    Eg:

    In my form I have to calculate the age of a participant based upon their age at the end of the calendar year.

    I want to set a date field as 31/12/YYYY to allow me to calculate ages as of that date in the current year. This year it would be 31/12/2015. Next year it would automatically be 31/12/2016. It makes the form more robust if the dynamic date is able to pick up the YYYY from the current year.

    Or is it less effort to just manually update the hidden field periodically?

    Thanks

    Ben

  • Mike_G JotForm Support
    Replied on November 21, 2015 at 8:01 PM

    The only way that we can get the Year only from the Date field is with the help of a few text fields and the Substring widget.

    Here's a sample form: https://form.jotform.com/53246757477973

    In the sample form, all of the other fields should be read-only except for the date fields so the conditions will work. And aside from the Birthday field and Age field all of the other fields should be hidden. The Substring widget can be hidden with the help of CSS injected in the form.

    How do I Create a dynamic date? Image 1 Screenshot 70

    Here are the conditions:

    How do I Create a dynamic date? Image 2 Screenshot 81

    Condition#1

    If "Birthday" field is filled then its value will be passed to "Get Birthday in DDMMYYYY format" field. This is important so that any input on the "Birthday" field with an incorrect format like 1-1-2015(January 1, 2015) instead of 01-01-2015 will be corrected when transferred to the "Get Birthday in DDMMYYYY format" field.

    Condition#2

    If "Get Birthday in DDMMYYYY format" field is filled, pass its string format to "Birthday String correct format" field. 

    Then we will use the string format value of "Birthday String correct format" field on the Substring widget(Get Birth year). 

    How do I Create a dynamic date? Image 3 Screenshot 92

    Condition#3

    If "Birthday String correct format" field is filled then it will pass the value of the Substring widget to the "Birth Year" field.

    Condition#4

    If "Birthday" is filled, pass its string format to "Current Date String correct format" field. 

    Same as the above, we will use the string format value of "Current Date String correct format" field on the Substring widget(Get Current year)

    How do I Create a dynamic date? Image 4 Screenshot 103

    Condition#5

    We will then pass the value of the Substring widget(Get Current year) to the "Current Year" field if any of the rules is met.

    How do I Create a dynamic date? Image 5 Screenshot 114

    Condition#6

    Since we have the birth year and the year of the current year. Create a condition that gets the age by subtracting the two.

    How do I Create a dynamic date? Image 6 Screenshot 125

    I would suggest you clone the sample form above using this guide: How-to-Clone-an-Existing-Form-from-a-URL to inspect the fields and the conditions.

    I hope this helps. Let us know if you need any further assistance or clarification with any of the instruction given above. Thank you.

  • DreamCalisthenics
    Replied on November 24, 2015 at 1:31 AM

    Yeah I was right - too hard! :-D

    Plus the age needs to be calculated at a specific date and not purely based upon year alone which is why I want to inject the year in a date field.

    But thanks for taking the time to explain it all. I'll certainly bookmark it for my 'To Do' list.

  • Chriistian Jotform Support
    Replied on November 24, 2015 at 3:27 AM

    On behalf of my colleague Mike_G, you are welcome. If you have any further questions, please feel free to contact us. Regards.