Skip to main content
richc32342209
Participant
March 17, 2019
Answered

Condition using a date less 3 years on a form

II a person enters a date, that is less than 3 years from today.  The message would open and when they close the message the form would also. The field is currently a date field m/dd/yy format.  No other validation or calculations currently set on the field. The field they would be entering the date in is called APPOINTMENTDATE. 

Any help would be greatly appreciated.

Thank you in advance.

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
March 17, 2019

You can use this code as the field's custom validation script:

if (event.value) {

    var d1 = util.scand("m/dd/yy", event.value);

    var d2 = new Date();

    d2.setFullYear(d2.getFullYear()+3);

    if (d1.getTime()<d2.getTime()) {

        app.alert("Error! The entered date is less than three years from today.");

        event.rc = false;

    }

}

6 replies

richc32342209
Participant
March 17, 2019

If I wanted to use a specific date say 4/01/16 would it be this

if (event.value) {

    var d1 = util.scand("m/dd/yy", event.value);

    var d2 = util.scand("m/dd/yy", 4/01/19);

        if (d1)<d2.) {

        app.alert("Error! At this time you are not Eligible to file this application. Your appointment date must be before April 1, 2016.");

        event.rc = false;

    }

}

Translate
try67
Community Expert
Community Expert
March 17, 2019

Almost. Change this line:

var d2 = util.scand("m/dd/yy", 4/01/19);

To:

var d2 = util.scand("m/dd/yy", "4/01/19");

Translate
try67
Community Expert
Community Expert
March 17, 2019

Also, change the line after that back to what it was...

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 17, 2019

You can use this code as the field's custom validation script:

if (event.value) {

    var d1 = util.scand("m/dd/yy", event.value);

    var d2 = new Date();

    d2.setFullYear(d2.getFullYear()+3);

    if (d1.getTime()<d2.getTime()) {

        app.alert("Error! The entered date is less than three years from today.");

        event.rc = false;

    }

}

Translate
richc32342209
Participant
March 17, 2019

If I wanted to use a specific date say 4/01/16 would it be this

if (event.value) {

    var d1 = util.scand("m/dd/yy", event.value);

    var d2 = util.scand("m/dd/yy", 4/01/19);

        if (d1)<d2.) {

        app.alert("Error! At this time you are not Eligible to file this application. Your appointment date must be before April 1, 2016.");

        event.rc = false;

    }

}

Translate