• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Condition using a date less 3 years on a form

Community Beginner ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

385

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 17, 2019 Mar 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;

    }

}

Votes

Translate

Translate
Community Expert ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

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;

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

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;

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

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;

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 17, 2019 Mar 17, 2019

Copy link to clipboard

Copied

LATEST

Thank you. With your help I adjusted the code and here is my final product that is giving me my results.

if (event.value) { 

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

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

    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; 

    } 

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines