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

Count days between dates and error message if exceeds 180

Community Beginner ,
Sep 22, 2017 Sep 22, 2017

Using Adobe Pro, I am trying to count days between two dates and if the total exceeds 180 days, I need an error message to pop up and require the user to adjust the dates until it is 180 days or less.  I have a StartDate, EndDate, and TotalDays. So far, I've been able to get the total days between two dates with a calc script:

var strStart = this.getField("StartDate").value;

var strEnd = this.getField("EndDate").value;

if(strStart.length || strEnd.length){

var dateStart = util.scand("mm dd,yyyy",strStart);

var dateEnd = util.scand("mm dd,yyyy",strEnd);

var diff = dateEnd.getTime() - dateStart.getTime();

var oneDay = 24*60*60*1000;

var days = Math.round(diff/oneDay);

event.value =days;}

What I can't figure out is how to add the additional calculation requirement to check the TotalDays field for 180 or less and have the error message .

TOPICS
Acrobat SDK and JavaScript , Windows
454
Translate
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 ,
Sep 22, 2017 Sep 22, 2017

How do you want to force them to do that, exactly? You can easily display an error message, using this code as the penultimate line in the above script:

if (days>180) app.alert("Error! The end date must not be more than 180 days after the start date.");

Translate
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 ,
Oct 02, 2017 Oct 02, 2017

Thanks!  that's pretty much what I was looking for.  Where in the script do I place the app.alert?

Translate
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 ,
Oct 02, 2017 Oct 02, 2017
LATEST

At the end of it, within the curly brackets of the if-statement.

Translate
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