Skip to main content
Inspiring
October 28, 2022
Answered

Cannot use directed Date format for date fields extracted to numeric value field

  • October 28, 2022
  • 1 reply
  • 492 views

It amazes me that anyone could become proficient at JS in acrobat let alone a subject matter expert.  As one issue is successfully addressed, it begets another new issue -- read headache. 😉

After failing to account for months w/ 31 days (and leap year) in my original scripting attempts, I have taken a different tack successfully addressing the 31 day problem... only to encounter a new problem. :S

The two (2) date fields sourcing the third field require a display/entry format of dd mmm yy with the third field displaying the numeric differential between the two (2) date fields.  Unfortunately, the third field errors out if I use anything other than a four digit year (i.e. yyyy) in the two (2) date fields.  My sincerest appreciation in advance for any and all assistance. 

 

The error: "Warning: JavaScript Window- XThe value entered does not match the format of the field [Deviation_Days_Actual_Start]

 

The script I've entered in the Deviation_Days_Actual_Start "Custom calculation script" area: 
var sDate1= new Date(this.getField("Actual_Date_Start").value);
var sDate2= new Date(this.getField("Proposal_Date_Start").value);
var date1 = new Date(sDate1.getFullYear(), sDate1.getMonth(), sDate1.getDate());
var date2 = new Date(sDate2.getFullYear(), sDate2.getMonth(), sDate2.getDate());
var millisecondsPerDay = 1000 * 60 * 60 * 24;
var millisBetween = date1.getTime() - date2.getTime();
var days = millisBetween / millisecondsPerDay;
var eDays = Math.floor(days)
event.value = eDays;

This topic has been closed for replies.
Correct answer JR Boulay

Try this script after adjusting the field names:

 

if (this.getField("Check In Date 3").value != "" && this.getField("Check Out Date 3").value != "") {
var dd = this.getField("Check In Date 3").value;
var rd = this.getField("Check Out Date 3").value;
var d1 = util.scand("dd mmm yy", dd);
var d2 = util.scand("dd mmm yy", rd);
var diff = (d2.valueOf() - d1.valueOf()) / 1000;
event.value = Math.round((diff / 60 / 60) / 24)+1;
}
else {event.value = "";}

1 reply

JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
October 29, 2022

Try this script after adjusting the field names:

 

if (this.getField("Check In Date 3").value != "" && this.getField("Check Out Date 3").value != "") {
var dd = this.getField("Check In Date 3").value;
var rd = this.getField("Check Out Date 3").value;
var d1 = util.scand("dd mmm yy", dd);
var d2 = util.scand("dd mmm yy", rd);
var diff = (d2.valueOf() - d1.valueOf()) / 1000;
event.value = Math.round((diff / 60 / 60) / 24)+1;
}
else {event.value = "";}

Acrobate du PDF, InDesigner et Photoshopographe
Inspiring
October 31, 2022

Outstanding and my sincerest thanks!