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

Add 36 hours to date and time and adobe form

New Here ,
Feb 01, 2017 Feb 01, 2017

Hi, I am trying to create a Adobe Form which automatically add 36 hours to the previous date and time entered in the dd/mm/yy HH:MM format. I was wondering if there is any advice on how to do that on Adobe acrobat DC?

TOPICS
Acrobat SDK and JavaScript
953
Translate
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 , Feb 04, 2017 Feb 04, 2017

This is a good example for why it's a bad idea to try to copy&paste your way to a JavaScript solution without a good background in how JavaScript works:

Joel's code assumed that you already had a variable (of type Date) named "previousDate". If that's the case, then this one line would add 36 hours. This would not get the previous date, and it would not set your current field to the result of that operation. You need to add more code around that one statement to come up with a solution that works

...
Translate
Community Expert ,
Feb 01, 2017 Feb 01, 2017

I created a JavaScript Date Library for Acrobat to make just such calculations much easier. It's free and has an installer.

The code would be...

previousDate.changeBy({"hours": 36});

Negative number reverse time.

The practicalPDF Date Library for Adobe Acrobat

Translate
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 ,
Feb 04, 2017 Feb 04, 2017

Hi Joel,

Thank you for your advice and suggested site. I have tried following the steps in your post and site but could not manage to do it. I am really sorry. I am still pretty new with regards to JavaScript.

I plan to create a form (as attached) where if I enter the date in 'Date1' in the format of dd/mm/yy HH:MM and the interval in 'Interval1' of 24, 36 or 48 hourly, i could create a pdf form where it could automatically add it together on 'Date2'. I tried using the suggested codebut it didn't work.

Any help would be very much appreciated. Thank you again for your help.

chart 2.png

Translate
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 ,
Feb 04, 2017 Feb 04, 2017

This is a good example for why it's a bad idea to try to copy&paste your way to a JavaScript solution without a good background in how JavaScript works:

Joel's code assumed that you already had a variable (of type Date) named "previousDate". If that's the case, then this one line would add 36 hours. This would not get the previous date, and it would not set your current field to the result of that operation. You need to add more code around that one statement to come up with a solution that works for you. We cannot teach you JavaScript, that is something that you need to learn on your own. Take a look here for some guidance about how to get started: Learning to Program JavaScript for Adobe Acrobat - KHKonsulting LLC

You need to be able to take something like Joel's answer and then build your own script around that. And for that, you need a good understanding of JavaScript.

Did you add Joel's library to your form? The solution he presented will not work without that library.

The following code should work by getting the date from a field named "Date1", and then calculating the value for another field:

// get the date from the field "Date1"

var dateString = this.getField("Date1").value;

if (dateString != "") {

    var previousDate = util.scand("m/d/yyyy h:MM tt", dateString);

    previousDate.changeBy({"hours": 36});

    event.value = util.printd("m/d/yyyy h:MM tt", previousDate);

}

else {

    event.value = "";

}

You need to adjust this to fit your specific form and field formats. If you have a problem with what certain JavaScript methods do, (e.g. util.scand() or util.printd()), look them up in the Acrobat JavaScript API documentation: Acrobat DC SDK Documentation

Translate
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 ,
Feb 04, 2017 Feb 04, 2017

Hi Karl,

thank you for your explanation and help.

Translate
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 ,
Feb 04, 2017 Feb 04, 2017
LATEST

Yes Karl, thanks for the further explanation. I was swamped on Friday and didn't see that more help was needed.

Translate
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