How do I create a validation to make sure that one date field is within a given range of another date field?

  • 23 January 2019
  • 4 replies
  • 60 views

Badge +1

I am creating a form with two date fields, Start Date and Expiration Date.  I need to make sure that the Expiration Date is within 365 days of the Effective Date.  IE Start Date 1/1/2019 Expiration Date 12/31/2019 is VALID, but Start Date 1/1/2019 Expiration Date 2/28/2020 is invalid. I tried creating a validation range where minimum value was set to Effective Date, then tried using the following formula for Maximum Value:

    =fn-LessThanOrEqual(fn-DateDiffDays(Start Date, Expiration Date), 365) 

Unfortunately, this always came back as false, no matter what date was entered.

I also tried creating a validation rule using this formula:

lessThanOrEqual(dateDiffDays(Start Date,Expiration Date),365)

This also seems to always fail, regardless of the Expiration Date entered.

I'm not sure how to proceed from here.  I'm new to formulas and functions in Nintex and could use some guidance.  Also, if anyone has a link to a good basic tutorial on creating this formulas, it would be helpful.  Thank you!


4 replies

Userlevel 5
Badge +8

You're formula is correctly setup, but you should just have to wrap the 365 in quotes so it will look like the below:

222675_pastedImage_2.png

Using this formula in a calculated value to show whether it evaluates correctly:

222676_pastedImage_3.png

222677_pastedImage_4.png

Thanks,

Dan

Badge +1

This is correct, I did need to add quotations around the 365 as shown above.  However, when making a validation rule in my version of Nintex forms, I also had to change from lessThanOrEqual to greaterThan.  The condition states that the control is INVALID if...  I was writing my control backwards, so after adding quotations, it would only validate if the expiration date was greater than one year from the start date.  Full correct formula in the validation rule control box:

222667_pastedImage_1.png

Badge +1

Also, make ABSOLUTELY SURE that you use "Named Controls" and not "Item Properties" when you are constructing this formula, or it will not work.  Not only will it not work, it will do all kinds of weird shit.  Wasted hours on that on another form today.  

Userlevel 5
Badge +8

Hi Michael,


Good call out on that one.  Item properties will be referencing the list item properties, which if the form has not been saved, will not be populated.  If you're using Item properties, you'll only want to use them on the 'Edit Form' options where the form has already been submitted.  The 'Named Controls' will be pulling what's in the form rather than the data stored to the list.

Thanks,

Dan

Reply