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

  • ajaudio
    Asked 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!

     

  • Jan
    Replied 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.

  • ajaudio
    Replied on April 29, 2015 at 2: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!

  • Ben
    Replied on April 29, 2015 at 3: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:

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

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

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

    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

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

    and then selecting Hide Field option

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

  • ajaudio
    Replied on May 1, 2015 at 10:56 AM

    Perfect, thanks for the workaround!