Copy link to clipboard
Copied
I've looked all over the community forums and tried a few things that people suggested
I am having trouble finding the right script to calculate the start date and count the total days the result shows in the end date.
Vacation PDF Formate
For Example
Vacation Start date = 01-04-2024 ="AnVac1"
Vacation Total Days = 30 days = "Total Days"
Vacation End Date = 30-04-2024="AnVac2"
I need result in Vacation End Date with script to calulate
I never have to work with scripts - just need some help this one time.
Copy link to clipboard
Copied
Try this as 'Custom calculation script' of "AnVac2" field:
var f1 = this.getField("AnVac1").valueAsString;
var f2 = this.getField("Total Days").valueAsString;
if (f1 && f2) {
var date = util.scand("dd-mm-yyyy", f1);
date.setDate(date.getDate() + (Number(f2) - 1));
event.value = util.printd("dd-mm-yyyy", date);}
else {
event.value = "";}
Copy link to clipboard
Copied
Are you looking for the total days, or the total working days?
I'm sure that it is possible to do that in Acrobat, but I'm not persuaded that Acrobat is the best application for this.
Copy link to clipboard
Copied
Yes result date is calculated after the total days
Hope someone help to solve this
Copy link to clipboard
Copied
This type of question has been asked (and answered) on these forums many times in the past. Try searching around and you're bound to find some answers, including the code needed to do it.
Alternatively, read these tutorials about working with Time and Date objects in Acrobat JS:
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2
https://acrobatusers.com/tutorials/working-date-and-time-acrobat-javascript-part-3-3
Or, if you just want a simple solution to your problem, you can use this (paid-for) tool I've developed that allows you to set it up very easily and quickly, without having to write any code:
https://www.try67.com/tool/acrobat-apply-automatic-date-calculation
Copy link to clipboard
Copied
TRY67 I saw many community this same message/thread.
Copy link to clipboard
Copied
Try this as 'Custom calculation script' of "AnVac2" field:
var f1 = this.getField("AnVac1").valueAsString;
var f2 = this.getField("Total Days").valueAsString;
if (f1 && f2) {
var date = util.scand("dd-mm-yyyy", f1);
date.setDate(date.getDate() + (Number(f2) - 1));
event.value = util.printd("dd-mm-yyyy", date);}
else {
event.value = "";}
Copy link to clipboard
Copied
Thanks a lot, Nessa Noorani for such accurate and remarkable support for resolving new people's queries.