Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Contributor ,
Oct 04, 2022 Oct 04, 2022

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

TOPICS
How to , JavaScript , PDF forms
397
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2022 Oct 05, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 05, 2022 Oct 05, 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.   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 05, 2022 Oct 05, 2022

I've finally managed to get the first one worked out!  Now moving onto getting the single field qualification and hopefully it won't be as painful.

Thank you BarlaeDC for your time.  It is truly appreicated.

Here was the final solution:

var sDate1= this.getField("Date_Start").value;
var sDate2= this.getField("Date_End").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));
var eDaysP = Math.abs(((oDate2-oDate1)/nDay));
var eDaysN = Math.abs(((oDate1-oDate2)/nDay));
if ((sDate1 && sDate2) && (sDate2 > sDate1)) {
event.value = Math.round(eDaysP);
} else if ((sDate1 && sDate2) && (sDate1 > sDate2)) {
event.value = Math.round(eDaysN) *-1;
} else {
event.value = "0";}
if (event.value <0) {
event.target.fillColor = color.red;
}
if (event.value >0) {
event.target.fillColor = color.green;
}
if (event.value ==0) {
event.target.fillColor = color.white;
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2022 Oct 06, 2022
LATEST

You should start here:

https://community.adobe.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&...


PDF Acrobatic, InDesigner & Photoshoptographer
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines