Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Date question : validate only if the given date is more than 10 days away

  • asilbering
  • asilbering's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 3 months ago - 1 year 3 months ago #239755 by asilbering
Please help us help you and fill where relevant:
Your LimeSurvey version:Version 3.28.43+221221
Own server or LimeSurvey hosting: own server
Survey theme/template: customized by my institution
==================
Hi!
I am using LimeSurvey Version 3.28.43+221221 with limited access to advanced configuration settings.
I have a Date/Time question and I would like a message to be displayed if the date chosen is less that 10 days away from the current date.
Example:
Current date : 23.01.2023
Chosen date : 25.01.2023
==> Displayed text : " Your course takes place in less than 10 days, please contact XXX".

Is it possible to do this with a validation equation? Is it possible to do this at all?

Thank in advance for any help!!

Best regards,

Ana


 
Last edit: 1 year 3 months ago by asilbering.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago #239759 by Joffm
Hi, Ana,

something like
{if(!is_empty(chosen) and floor((strtotime(chosen)-strtotime('now'))/(60*60*24))<10,"Your course takes place in less than 10 days, please contact XXX","")}





Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: asilbering

Please Log in to join the conversation.

  • asilbering
  • asilbering's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 2 months ago - 1 year 2 months ago #239775 by asilbering
Hi Joffm,
Thanks for your quick reply and your help! I have tried your equation in my question and unfortunately it doesn't work.
The variable "chosen" is not recognized...
I have tried adding inverted commas but that didn't do the trick either (the equation seems fine in that case but no message is displayed)... any suggestions? The test survey is attached, just in case. Is it possible that any features need to be activated in the theme to allow the equation to work?
Please let me know if you need any further information.
Thanks again for your help!
Have a nice day, Ana
 
Last edit: 1 year 2 months ago by asilbering. Reason: Weird code replaced the image

Please Log in to join the conversation.

More
1 year 2 months ago #239779 by jelo

The variable "chosen" is not recognized...
 
You need to replace chosen with the questioncode of your question.

In your testsurvey you replace "chosen" with "testdate".
 

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in to join the conversation.

More
1 year 2 months ago - 1 year 2 months ago #239780 by jelo
Updated answer: The question validation equation contains the equation and the question validation tip the text.
The validation is to ensure the right values. In your case every future date with more than 9 days away from the current date.

The equation Joffm has posted is for the question validation tip or can be used in the question text.
Which would just be a warning without blocking answering the question via the validation (which has to formulated to become true when answer is valid).




 

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Last edit: 1 year 2 months ago by jelo.

Please Log in to join the conversation.

More
1 year 2 months ago #239783 by jelo
Take a look at the modified survey. Might be still buggy, but check.

Question validation (More than 10 days)
Code:
( ! is_empty(testdate) and floor((strtotime(testdate) - strtotime('now')) / (60 * 60 * 24)) > 10)

Question validation tip (less than 11 days)
Code:
if( ! is_empty(testdate) and floor((strtotime(testdate) - strtotime('now')) / (60 * 60 * 24)) < 11, "Your course takes place in less than 11 days, please contact XXX", "")
 

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: asilbering

Please Log in to join the conversation.

  • asilbering
  • asilbering's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 2 months ago #239804 by asilbering
Hi Jelo,

thanks a lot for the explanations, it works wonderfully! I have used both, the validation equation and the validation tip (for the latter I had to add curly brackets).

I had not realized that "chosen" in Joffm's example was the question code.

Thanks you both for your valuable help!! The support of this community is invaluable!

Have a nice day.

Ana

Please Log in to join the conversation.

  • asilbering
  • asilbering's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 2 months ago #239834 by asilbering
Hi !
Just to complete the info for other interested people:

I found a third option proposed by Joffm in a different thread :
One can use the "minimum date" field of the "display" pane.

Valid values

- Any date value in format YYYY-MM-DD (eg., 2017-08-24);
- Any year value;
- Any English string : "now", "-10 years", "tomorrow";
- Reference to another date/time question : AnotherDateQuestion (using the question code);
- Expressions : With expressions, a minimum date can be dynamically calculated. For example, you can use a date from a previous answer + 3 days as a minimum for the present question by entering: date("Y-m-d",strtotime(departuredate)+3*60*60*24).

Have a nice day!
Ana
The following user(s) said Thank You: jelo

Please Log in to join the conversation.

  • asilbering
  • asilbering's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 2 months ago - 1 year 2 months ago #239874 by asilbering
Hi again,
I am experiencing some weird behavior when using "minimum date" together with an "IF clause" in the question text (see attached question) (the browser I am using is Firefox but the same thing happens with Chrome).
If I set min_date to ' 2 days' and choose the date of today 2 days (that is January 29th, see Image1), the warning of the IF clause is not displayed (but it should because we are less than 10 days away). Does anybody have an explanation/solution for this behavior, please?

If I then change to January 30th all works fine (my warning is displayed, Image2).
 
When I then go back to the 29th my warning is displayed together a second warning message saying that you can only chose dates higher or equal to the 29th (Image3). Is it possible to hide the second warning message?

Thanks in advance.
Best,
Ana
Last edit: 1 year 2 months ago by asilbering.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose