Skip to main content
dhhsc84757271
Known Participant
September 22, 2017
Question

Count days between dates and error message if exceeds 180

  • September 22, 2017
  • 1 reply
  • 534 views

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 .

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 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.");

dhhsc84757271
Known Participant
October 2, 2017

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

try67
Community Expert
Community Expert
October 2, 2017

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