- ajaudioAsked 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.
- JotForm SupportJanAnswered on April 29, 2015 at 12:54 PM
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.
Hope this helps. Thank you.
- ajaudioAnswered 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.
- BenAnswered 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
- ajaudioAnswered on May 01, 2015 at 10:56 AM
Perfect, thanks for the workaround!