Copy link to clipboard
Copied
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 .
Copy link to clipboard
Copied
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.");
Copy link to clipboard
Copied
Thanks! that's pretty much what I was looking for. Where in the script do I place the app.alert?
Copy link to clipboard
Copied
At the end of it, within the curly brackets of the if-statement.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now