What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.

  • Profile Image

    Widget to compare two dates?

    Asked by emedpeds on April 24, 2015 at 07: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

  • Profile Image
    JotForm Support

    Answered by Charlie on April 25, 2015 at 04: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".

    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.

    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".

    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.


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