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

Subtract multiple various days from date input by user

Community Beginner ,
Nov 07, 2019 Nov 07, 2019

So, as ignorant and ineperienced as I am, I spent the last three days browsing these topics and still have to clue how to calculate (and display) a date into one field that is 180 days from a date that is input by the user.

 

I've read a ton about the 'get' function and can't even get a wrong date to display in my results field.

 

When I click on the suggested "Read everything on this page" links it does nothing for me. I'm totally ignorant...

TOPICS
Create PDFs , PDF forms
2.4K
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 ,
Nov 07, 2019 Nov 07, 2019

Have you seen these tutorials? They're a good starting point to learning how to work with Date objects in Acrobat (which is not a simple task):

https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2
https://acrobatusers.com/tutorials/working-date-and-time-acrobat-javascript-part-3-3

 

If you're interested in an easy way of doing it I can recommend my own (paid-for) tool that allows you to quickly set up such calculations, without having to write any code at all. You can find it here: http://try67.blogspot.com/2012/01/acrobat-apply-automatic-date.html

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 Beginner ,
Nov 07, 2019 Nov 07, 2019

Yep, been over that. It's all greek to me, but if I can't figure it out I might be lost!

 

I'll get back at it

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 ,
Nov 07, 2019 Nov 07, 2019

Date calculations are tricky because dates are not single valued entities. Actually though, they are. It's just that we view dates and times in a complicated way, using day, month, and year values. The idea behind any date calculation is to convert the date representation into a single number, then add or subtract a quantity, and finally convert it back to the date representation. The conversions are pretty complicated, but we don't have to worry about it because JavaScript provides us with conversion functions, util.scand and util.printd.

 

You're calculation script should be something like this.

 

var dateIn = util.scand("...", getField("Date").value);

var newTime = dateIn.getTime() + value180days;

event.value =   util.printd("...", new Date(newTime));

 

All you need to do is fill in the "..." bits and calculate "value180days"

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Nov 09, 2019 Nov 09, 2019

Seriously, if I can't figure it out from the advice you guys give here, then I deserve to have to pay someone else to do it for me!

 

Thanks a bunch 🙂

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 Beginner ,
Nov 09, 2019 Nov 09, 2019

So, since I'm an idiot and I refuse to give up despite still not being able to figure it out, I did a screen cap of what I'm trying to do with the field names, etc, to try to see if I can figure out the part that goes in between the "..."

Also, a lot of the tutorials I'm looking at are in the JavaScript debugger - is this in the JavaScript editor from the Custom calculation script option in the current version of Adobe?

 

Thanks a million in advance!Untitled drawing.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 ,
Nov 09, 2019 Nov 09, 2019
LATEST

You'll find a tutorial on the Console window here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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