Skip to main content
richc32342209
Participant
March 17, 2019
Answered

Condition using a date less 3 years on a form

  • March 17, 2019
  • 2 replies
  • 577 views

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 has been closed for replies.
Correct answer try67

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;

    }

}

2 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;

    }

}

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");

try67
Community Expert
Community Expert
March 17, 2019

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

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;

    }

}

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;

    }

}