Validation Rule to Check Day of Date?

  • 29 August 2014
  • 8 replies
  • 3 views

Badge +3

Within Nintex Forms 2013, I am looking to verify a date that was selected is actually a Sunday, and not another day of the week. I have the following in a validation rule on the date control, but it doesn't appear to fire when the form is submitted. What am I missing?

 

contains(formatDate({Self},D),"Sunday") == "0"

 

Thanks!

Jess


8 replies

Userlevel 7
Badge +11

Hi Jess,

as a work around for now, add a Calculated Value control (call it something like MyCV) onto your form and configure with something like this:

contains(formatDate(MyDate,'D'),'Sunday')

Where MyDate is the name of your date control.

Then in your validation rule, set it to:

not(equals(MyCV,'true'))

This should work for you.  I'll look into why all of that in a Validation Rule isn't working and will get back to you.

cheers,

Vadim

Badge +6

Hi Jess,

 

the formula itself is almost correct. It is just missing the quotation marks "D". By using "D' it will return a string like this: "Thursday, August 28, 2014" in which case you can use the contains() function.

 

contains(formatDate({Self},"D"),"Sunday")

 

If you are just interested in the day I'd recommend using:

 

equals(formatDate({Self},"dddd"),"Sunday") -> "dddd" will format the date as just the day's name, "Sunday" for example.

 

In either case, the formula will return TRUE (i.e. show the error message you specified) if the day is Sunday and FALSE (i.e. the error message will not be shown) if the day is not a Sunday, so the comparison in your formula is not required.

 

Hope that helps,

Pat

Userlevel 7
Badge +11

That's awesome Pat. I wonder why our other formula didn't work. Thanks for sharing the solution.

Badge +6

Not sure which reply you read, but I edited the first reply. The only thing in the original formula that was missing was the quotation marks aorund the "D" happy.png

Userlevel 7
Badge +11


aahh I didn't see that. Thanks Pat.

Badge +3

Thank you Pat and Vadim! Thanks for catching the typo in my original post, and then showing me a better validation check. I modified it slightly for my case, in which I want to say the date is invalid if it is not a Sunday:

not(equals(formatDate({Self},"dddd"),"Sunday") )

Thanks again!

Jess

Badge +6

that will be a rather long expression as you'd need to combine the above with OR statements for each day of the week and another regular expression to check for the time range. This will get rather ugly. You'd be better served creating your own inline function that does that as part of the code. If you need advise on how to create your own inline function, please refer to this article.

Badge

contains(formatDate({Self},'D'),'Monday') == "0"

This works for me. Thanks.

Reply