Skip to main content
traviss52897766
Participant
July 27, 2017
Answered

Adding number of days to date field

  • July 27, 2017
  • 1 reply
  • 1149 views

I am making a document that generates pay periods and the numbers get off when I get to Daylight Savings Time. When I enter the first date, the next box adds 13, the next adds 1 to start the next pay period, next 13, and so on. I am calculating this using milliseconds and was wondering if I can add something to disable DST or at least calculate is using days so this wouldn't be a problem. Can anyone help me?

This topic has been closed for replies.
Correct answer try67

MM/DD/YY, in one box I want to add 1, in another box I want to add 13. If I can get the first line I can figure out the rest of the rows!


Use this code as the custom calculation script of the second field:

// Add one day

var s = this.getField("BPP").valueAsString;

if (s=="") event.value = "";

else {

    var d = util.scand("mm/dd/yy", s);

    d.setDate(d.getDate()+1); // replace 1 in this line with any other number you wish to add...

    event.value = util.printd("mm/dd/yy", d);

}

PS. I've developed a tool that allows you to set up such calculations easily and without having to write any code. It also has an option to automatically skip weekends and a custom-defined list of holidays. If you're interested you can find it here: Custom-made Adobe Scripts: Acrobat -- Apply Automatic Date Calculation

1 reply

try67
Community Expert
Community Expert
July 27, 2017

Yes, this is a common problem. Instead of adding days using milliseconds you should use the setDate method. For example:

var d = new Date();

d.setDate(d.getDate()+1);

This code will add one whole day to the d variable, regardless of the hours.

traviss52897766
Participant
July 27, 2017

So the only input the end user will be doing with the dates is the box "BPP". How would I incorporate this into the script you gave me? I'm sorry, this is all new to me!

try67
Community Expert
Community Expert
July 27, 2017

How many days do you want to add, and what's the format of the dates?