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

    How to see if one date is before the other or if they are set in the same time?

    Asked by ajaudio on April 29, 2015 at 10:11 AM

    Is it possible to have a condition that compares two date fields entered by the user?

    For example, is date 1 = date 2.  Or is date 1 before date 2?  I an new to Jotforms but the only option I see is to enter a specific date in the condition.  Perhaps I'm missing a basic syntax for this.

    Thanks!

     

    date field dates conditions
  • Profile Image
    JotForm Support

    Answered by Jan on April 29, 2015 at 12:54 PM

    Hi,

    May I ask what are you trying to achieve with your form? Are you planning to compare 2 dates entered by the user? Like 2 dynamic values?

    Date is considered as a dynamic value which is why there is no "Equal to" option in the conditions. You can use the "Equal to" option on a regular text box and by using static values.

    I would recommend you to create a static value wherein it can be compared to a dynamic value. For example, you will set a static value like (04/30/2015). Then use the conditions like "equal to, not equal to, before and after" to compare the dynamic value to the static one.

    Related guide: http://www.jotform.com/help/57-Smart-Forms-Using-Conditional-Logic

    Hope this helps. Thank you.

  • Profile Image

    Answered by ajaudio on April 29, 2015 at 02:57 PM

    Thanks for the response.  Yes, my intent was for a client to enter 2 events.  Then have dates for each event.  I was hoping to have a way to determine whether the events fell on the same day or different days.

    So, if I understand you correctly the only way to accomplish this would be either

    1) Have a user enter both dates as a text box

    2) Have a user pick one date from a calendar (dynamic) and enter the other date in a text box

    There's no way to compare two date fields.

    Thanks!

  • Profile Image

    Answered by Ben on April 29, 2015 at 03:57 PM

    Actually dates are numbers and with numbers we can play around, so basically what you wish to do is to see if date A is different than date B and in what way.

    Easy if you know the little tricks that JotForm allows you to do, just do the following - turn it into math:

    A - B = x

    if x == 0 (equal to 0, pardon the programming slang) - the dates are equal

    if x < 0 - the B date is bigger than A

    if x > 0 - the A date is bigger than B

    What does this tell us? It tells us if they are the same, but also tells us which is the bigger one where 2015-Apr-29 (for example) is bigger date than 2015-Apr-01.

    Also 2015-May-19 is bigger than 2014-August-25.

    So lets see how we can glue it all together

    First we add 2 date fields and then add Form Calculation widget that will subtract B from A like so:

    OK, now all we need is a bit of conditions to do the checks - yup that is all there is to math :'(

    And that is it.. :)

    You can see it all here: http://form.jotformpro.com/form/51185750155959

    and you can clone it to your account by following the steps here: How to Clone an Existing Form from a URL

    Do let us know if that is what you were after.

    I have of course hidden Form Calculation since that is how you would have it on your own form and you can do that by simply clicking on it and then clicking on little gear wheel in the quick action toolbar

    and then selecting Hide Field option

  • Profile Image

    Answered by ajaudio on May 01, 2015 at 10:56 AM

    Perfect, thanks for the workaround!