How to count days from today and use it in conditional logic?

  • iconic_productions
    Asked on April 24, 2020 at 6:50 AM

    In one of my forms, I am trying to find a way where if a date field entry exceeds for than 21 days from the calendar date of today it opens up two additional hidden fields. 

    is this possible and if it is how do I do set it up?

  • Bojan Support Team Lead
    Replied on April 24, 2020 at 8:35 AM

    Greetings and thank you for your message.

    I have created a test form for you on the following link:
    https://form.jotform.com/201143535667050

    You first need to add new Date Picker and set it to show current date by default. You can hide this field if you don't want it to be visible.

    How to count days from today and use it in conditional logic? Image 1 Screenshot 50

    Then you need to add Form Calculation widget to your form. In it, you need to subtract the date that the user has inputted from the current day. This will give you the difference between those days. 

    How to count days from today and use it in conditional logic? Image 2 Screenshot 61

    Finally, using conditional logic, you can use Show/Hide fields to show the fields you wish to be visible if the calculated value is greater than 27:

    How to count days from today and use it in conditional logic? Image 3 Screenshot 72

    You can configure the condition like this:

    How to count days from today and use it in conditional logic? Image 4 Screenshot 83

    Feel free to clone my form to see the conditions and calculations. You can click here to see how you can do that.

    You can click here to learn more about form calculations, and click here to learn more about conditional logic.

    Please let us know if there is anything else we can help you with.

  • iconic_productions
    Replied on April 24, 2020 at 9:28 AM

    Hi Bojan,

    I tried doing what you said, but when I tested it and inputted the date, the hidden field does not display.  Here is the form it is in.

    https://form.jotform.co/.../notification/...

  • iconic_productions
    Replied on April 26, 2020 at 5:49 PM

    Hi, can someone please help me.  

  • Elton Support Team Lead
    Replied on April 26, 2020 at 9:24 PM

    In your form, it is not possible to select future dates only past dates so you can't have 21 days in the calculation.

    How to count days from today and use it in conditional logic? Image 1 Screenshot 30

    I believe you've interchanged your date limit in the field settings. The Future should be checked instead of the Past.

    How to count days from today and use it in conditional logic? Image 2 Screenshot 41

    If that's intentional then you have to switch the fields in your calculation formula. It should be Current Date - Actual Date

  • iconic_productions
    Replied on April 26, 2020 at 9:28 PM

    It still does not work.  I change the calculation to be Today's Date (minus) Actual Date of Incident.  I then created the conditional format that if calculation is less than 0 to show the hidden fields.

    And when I test it in preview it did not do that.

    What I am try to do is when the user fills out the form, if the Actual incident date is more than 21 days from today (whatever the date of today is) it shows a field that asks them to explain why it took 21 days to complete the form.

    This means the Actual incident date cannot be a date in the future, and that is why I unchecked the future box.

    Please help.

  • iconic_productions
    Replied on April 27, 2020 at 4:56 AM

    Your assistance would be greatly appreciated.

  • Bojan Support Team Lead
    Replied on April 27, 2020 at 9:00 AM

    Thank you for your reply.

    When you subtract Today's date with the Day of the incident, you will get a positive number showing the difference between the days. Therefore, in your condition, you should not test if the result is less than zero. You should test if the result is greater than 21.

    How to count days from today and use it in conditional logic? Image 1 Screenshot 20

    If it is, it means that the number between the current day and the selected day is greater than 21, and the field will be shown. 

    If you wish to check if the difference is 21 or more, you can set value in the condition to be 20.

    Please test this, and let us know if this works for you.

    Thank you for your cooperation. 

  • iconic_productions
    Replied on April 27, 2020 at 7:30 PM

    Hi Bojan, that works, however it creates another problem.  As I have the Actual Date set to None, when the form is opened it automatically shows the hidden field explanation textbox.  I don't want this to occur.  I only want the hidden textbox to display when they enter a date in the Actual Date field and that date is calculated to be more than 21 days from the current Todays Date.

    Is there a way to do this.

  • Elton Support Team Lead
    Replied on April 27, 2020 at 8:48 PM

    It is working fine when I tested your form here. These 2 fields stay hidden when I reload your form. They are only shown when I changed the actual date that's more than 21 days.

    How to count days from today and use it in conditional logic? Image 1 Screenshot 30

    Example:

    How to count days from today and use it in conditional logic? Image 2 Screenshot 41

  • iconic_productions
    Replied on April 27, 2020 at 8:54 PM

    That is because I changed the Actual Date to have the default date setting of today.  I don't want this.  I want the actual date field to have the default setting for the date to be None.  When I have it set to None the hidden fields display.

  • Elton Support Team Lead
    Replied on April 27, 2020 at 9:00 PM

    I see, thanks for clarifying that. The fix is easy,

    1. First, set the default value of the actual date to NONE

    2. In its existing condition, add another IF rule like the following:

    If Actual Date is filled then select If ALL rules matched

    Example:

    How to count days from today and use it in conditional logic? Image 1 Screenshot 20

  • iconic_productions
    Replied on April 27, 2020 at 9:10 PM

    That worked wonders.  Best support of any company I have ever experienced.  Thank you for your help.

  • iconic_productions
    Replied on April 27, 2020 at 9:28 PM
    Your email has been received and place in a queue. Due to the global coronavirus pandemic, staff in this department are not available and this department has been closed indefinitely. Only Department and Channel Supervisors are available and monitoring all messages. Major delays are expected to occur and we apologize in advance. Currently, the delay is estimated at 2-5 days. In the meantime, you may be able to find your answer in the company’s FAQ and Knowledge Server or at the company main webpage banners.
    This is unprecedented times for everyone and we are doing our very best to support and assist all our customers, suppliers, contractors, and staff. We ask for patience and understanding and ask that you please follow all company and government directions with regards to hygiene procedures and look after yourself and family and stay safe.
    ...