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

Adding number of days to date field

New Here ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

771

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jul 27, 2017 Jul 27, 2017

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 wee

...

Votes

Translate

Translate
Community Expert ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
New Here ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

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!

1.png

Votes

Translate

Translate

Report

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 ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
New Here ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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
New Here ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

Basically this is what I was using. I found it online and changed only the things I had to.

 

event.value = "";

var strDate = this.getField("Pay Period WeekRow1_2").value;

{

  var oDate = util.scand("mm/dd/yy",strDate);

  if(oDate)

  {

    var fiveDays = 1 * 24 * 60 * 60 * 1000;

    oDate = new Date(fiveDays + oDate.getTime());

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

}

}

Votes

Translate

Translate

Report

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 ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
New Here ,
Jul 27, 2017 Jul 27, 2017

Copy link to clipboard

Copied

LATEST

Awesome, that worked great. Thank you so much!

Votes

Translate

Translate

Report

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