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

PDF Form - Date increase / decrease - Does not always run in time

Community Beginner ,
Mar 24, 2017 Mar 24, 2017

Copy link to clipboard

Copied

Hello fellow Acrobat users ...

This is my first post, so please forgive me if i am too detailed or not detailed enough

My question is ... Why does the formula not work consistency?

Thank you very mush in advance for your help

I have created a form that allow a single field to populate other fields

Field 1       A date is entered e.g. 01- apr 2017

Fields 2-8 - Whatever is entered into Field 1 is auto-populated into fields 2-8 ... minus 1 day starting from 8 back through to 2, incrementing

Using the format "dd - mmm - YYYY" ... mmm is Caps on first letter

e.g.

Field 1     03 apr 2017

Field 2     28 Mar 2017 - Matches Field 1 ... - 6

Field 3     29 Mar 2017 - Matches Field 1  ... - 5

Field 4     30 Mar 2017 - Matches Field 1  ... - 4

Field 5     31 Mar 2017 - Matches Field 1  ... - 3

Field 6     01 Apr 2017 - Matches Field 1  ... - 2

Field 7     02 Apr 2017 - Matches Field 1  ... - 1

Field 8     03 Apr 2017 - Matches Field 1  ... - 0

All has been working fine but i have just noticed that if i put the following into Field 1 "31 mar 2017" ... the following dates are auto-populated but skips 26 Mar 2017 - after 25 and before 27

Field 1     31 mar 2017

Field 2     24 Mar 2017 - Saturday

Field 3     25 Mar 2017 - Sunday

Field 4     27 Mar 2017 - Monday

Field 5     28 Mar 2017 - Tuesday

Field 6     29 Mar 2017 - Wednesday

Field 7     30 Mar 2017 - Thursday

Field 8     31 Mar 2017 - Friday

The Javacript i am using is shown below

Line 6 - the number in bold, is changed per cell

i.e. FRIDAY

var strStart = this.getField("DateStart").value;

if(strStart.length)

{

  var dateStart = util.scand("dd mmm yyyy",strStart);

  var oneDay = 24 * 60 * 60 * 1000;

  var dueMillis = dateStart.getTime() + -0 * oneDay;

  var dueDate = new Date(dueMillis);

  event.value = util.printd("dd mmm yyyy",dueDate);

}

else

  event.value = "NA";

i.e. MONDAY

var strStart = this.getField("DateStart").value;

if(strStart.length)

{

  var dateStart = util.scand("dd mmm yyyy",strStart);

  var oneDay = 24 * 60 * 60 * 1000;

  var dueMillis = dateStart.getTime() + -4 * oneDay;

  var dueDate = new Date(dueMillis);

  event.value = util.printd("dd mmm yyyy",dueDate);

}

else

  event.value = "NA";

TOPICS
Edit and convert PDFs

Views

795

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 Beginner , Mar 24, 2017 Mar 24, 2017

2 things

1 - Thank you for an amazingly swift reply

2 - GENIUS!!!

Many many thanks!

Votes

Translate

Translate
Community Expert ,
Mar 24, 2017 Mar 24, 2017

Copy link to clipboard

Copied

Because of the change to day-time savings, which adds an extra hour on the 26th.

The solution is to change the code so that it adds a full day instead of a day calculated in milliseconds. So, for example, to add one day you would use this code:

var dateStart = util.scand("dd mmm yyyy",strStart);

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

var dueDate = new Date(dateStart.getTime());

event.value = util.printd("dd mmm yyyy",dueDate);

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 Beginner ,
Mar 24, 2017 Mar 24, 2017

Copy link to clipboard

Copied

2 things

1 - Thank you for an amazingly swift reply

2 - GENIUS!!!

Many many thanks!

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 Beginner ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

Hello try67,

I appreciate your help but ...

I have tried but failed to implement your code into my PDF

What i actually did was change the number 24 to 23

var oneDay = 24 * 60 * 60 * 1000;

It works for +1 and -1 hour on BST March and October as well as other dates

Not as "neat" as it could be but hey, it works

Can you confirm i am not being stupid please?

Thanks

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 ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

What didn't work with the code I provided?

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 Beginner ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

🙂

Didn't know where to put it

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 ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

Inside the curly brackets, replacing what you currently have... So for Friday it would be:

var strStart = this.getField("DateStart").value;

if (strStart.length) {

    var dateStart = util.scand("dd mmm yyyy",strStart);

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

    var dueDate = new Date(dateStart.getTime());

    event.value = util.printd("dd mmm yyyy",dueDate);

} else event.value = "NA";

By the way, I would put this code in a function and pass to it the number of days to add as a parameter, instead of writing out the exact same code for each day of the week, only with one minor difference. Will make implementing changes like this much more easy, too...

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 Beginner ,
Apr 01, 2017 Apr 01, 2017

Copy link to clipboard

Copied

LATEST

Hello try67,

To be honest you have kinda lost me ...

I have used the code you provided and it works a treat!

Coping and pasting the code into the other 6 cells and then adjusting the increment at the end of line 4 wasn't an issue

Maybe, if and when I go deeper into JavaScript it will make sense!

Once again, many thanks for you swift and helpful replies

Enjoy your weekend!

Rgds Mark

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