Skip to main content
Inspiring
October 4, 2022
Question

Calculate the numeric differential between two date fields and display in in a third field

  • October 4, 2022
  • 2 replies
  • 503 views

I have now spent two weeks on attempting to accomplish this with varying scripts found here -- to include mixing and matching -- to no avail.  Theoretically, it seems simple enough but is clearly beyond my level of understanding or capability.  I am technically attempting to achieve two different outcomes and to my untrained eye they appear as if they would be similar, yet both lead me to a highball of bourbon at the end of my day. 😉

I have a form with multiple date fields -- some are essentially paired (i.e. "start_date" and "end_date) and another is stand-alone (i.e. "fixed_date").

For the paired, I am attempting to calculate the differntial into either a negative or positive digit with the resulting number of days displaying in a third field in either red (negative) or black (positive).

For the single, I am attempting to have a date displayed in one of three colors based on the required periodicity of a qualification.  Some quals expire after one year so I'm trying to display the date in either black (greater than 30 days to expiration), yellow (within 30 days of expiration), and red (qualification expired). 

My sincerest thank in advance for any and all assistance.

Very Respectfully,
Charlie

This topic has been closed for replies.

2 replies

JR Boulay
Community Expert
October 6, 2022
BarlaeDC
Community Expert
October 5, 2022

Hi,

 

Are you able to share your attempts and then we can guide how to fix that?That way we can make sure we fix it for your form and make it easier for you to maintain it.

Inspiring
October 5, 2022

Unfortunately, I am unable to share -- the delayed response was awaiting permission. Suffice it to say, my attempts to make lemondade from the bushel of lemons dumped on my lap is not panning out. :S

My starting point was attempting to use the following scripts obtained from these forums:
var sDate1= this.getField("Date_Start_Actual").value;
var sDate2= this.getField("Date_Start_Contract").value;
var oDate1 = util.scand("ddmmmyy", sDate1);
var oDate2 = util.scand("ddmmmyy", sDate2);
var nDay = 1000 * 60 * 60 * 24;
var eDays = Math.abs(1+((oDate2-oDate1)/nDay));
if (sDate1 && sDate2) && (sDate1 != sDate2) {
event.value = Math.round(eDays);
} else if (sDate1 && sDate2) && (sDate1 == sDate2) {
event.value = "1";
else {
event.value = "";

and 

var theColor = color.black;
if (event.value < 0) {
theColor = color.red;
}
else if (event.value < 10) {
theColor = color.yellow;
}
else {
theColor = color.black;
}

event.target.fillColor = theColor;

I have about a half dozen other scripts also from these forums that I've attempted to add in whole or in part and haven't been able to get past the "Syntax Error" to test -- unlike the two above.  Folks have now come to prefer the fillable acrobat forms vice the spreadsheets we've been using but they are demanding more and more functionality.