Widget to compare two dates?

  • emedpeds
    Asked on April 24, 2015 at 7:00 PM

    is there a widget for start and end dates that prevents choosing an end date earlier then the start date? Trying to prevent a time or date period error

  • Charlie
    Replied on April 25, 2015 at 4:25 AM

    You can achieve this by using conditional logic and the form calculation widget, here's an example of my form: http://form.jotformpro.com/form/51141426449957 

    So basically, when you add an end date earlier than the start date it will show you an error message and hides the submit button. Here's how I setup mine:

    1. These are the things that I added in my form:

    a) a "Text" field under Form Tools section that will act as the error message.

    b) Two default date fields that we will be comparing.

    c) Add a form calculation widget and name it "Date Difference", this is where we will calculate between Start Date and End Date.

    d) The "Conditions" option to where we will compare the result in the "Date Difference".

    Widget to compare two dates? Image 1 Screenshot 50

    2. In my Form calculation widget, this is my formula:

    End Date - Start Date = the difference between them.

    You can use the "Add Fields" button to add the fields and perform a calculation.

    Widget to compare two dates? Image 2 Screenshot 61

    3. After that, go to your "Conditions" and setup a condition. I'll choose the first option which is to "Show / Hide a form field".

    Widget to compare two dates? Image 3 Screenshot 72

    4. This is how I setup my rules and what actions to take place.

    So basically, if the date difference is less than "0", which means a negative value, it will show the error message and hide the submit button. When you get a negative value in the date difference, it means that the end date is earlier than the start date.

    Widget to compare two dates? Image 4 Screenshot 83

     

    Do let us know if you need more help on this.

    Thanks