Skip to main content
dhhsc84757271
Known Participant
Sep 22, 2017 3:22 PM UTC
Question

Count days between dates and error message if exceeds 180

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 is closed to new replies. Start a new post to keep the conversation going.

3 replies

try67
Community Expert
Community Expert
Sep 22, 2017 3:43 PM UTC

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
dhhsc84757271
Known Participant
Oct 2, 2017 4:11 PM UTC

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

Translate
try67
Community Expert
Community Expert
Oct 2, 2017 4:22 PM UTC

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

Translate