Skip to main content
traviss52897766
Participant
Jul 27, 2017 3:06 PM UTC
Answered

Adding number of days to date field

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 is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Jul 27, 2017 3:44 PM UTC

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

7 replies

try67
Community Expert
Community Expert
Jul 27, 2017 3:20 PM UTC

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.

Translate
traviss52897766
Participant
Jul 27, 2017 3:29 PM UTC

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!

Translate
try67
Community Expert
Community Expert
Jul 27, 2017 3:34 PM UTC

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

Translate