Calculate future dates

I have set up my form to add in the date of the form the field is "Today" I would like to add 3 other fields that autopopulate the dates for 2 weeks from "today", 6 weeks from "today" and 10 weeks from "today"


Xenia D'Souza


2 Answers

Basically you can do this by getting the current value of the "Today" field, converting it to a Date object (using util.scand()), and then manipulating that object by adding the amount of time you want to it, and using that as the value of your target field(s) (using util.printd()).
Thom Parker has written a set of tutorials on this subject: http://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascr
ipt


Another option, if you don't want to spend a lot of time on studying how to write this code, is to use this tool I developed just today. It will basically do the same, but is much more intuitive to use and doesn't require any programming knowledge... Have a look here, if you're interested:
http://try67.blogspot.com/2012/01/acrobat-apply-automatic-date.html


Gilad D (try67)   

This can be done, for sure.

The question of the triggering event would have to be discussed; it could either be when the form opens, or when the user clicks on a button. We also assume that the format for the dates should be "mm/dd/yyyy". The fields for the date shall be called "today", "intwoweeks", "insixweeks", and "intenweeks".

We then could use something like this script:

var today = new Date() ;
this.getField("today").value = util.printd("mm/dd/yyyy", today) ; // fills field for today
this.getField("intwoweeks").value = util.printd("mm/dd/yyyy", new Date(today.getFullYear(),today.getMonth(),today.getDate()+14)) ; // fills field for today in two weeks
this.getField("insixweeks").value = util.printd("mm/dd/yyyy", new Date(today.getFullYear(),today.getMonth(),today.getDate()+42)) ; // fills field for today in six weeks
this.getField("intenweeks").value = util.printd("mm/dd/yyyy", new Date(today.getFullYear(),today.getMonth(),today.getDate()+70)) ; // fills field for today in ten weeks

Note that we have long lines; after the variable definition, each line begins with "this.getField…"

And that should fill your field correctly.

Hope this can help.


Max Wyss   


Please specify a reason: