Insert current date in text field with 'todays date' and one with 'todays date + 4 weeks'.

I need two text boxes, one with "todays date" and one with "todays date + 4 weeks" (or 28 days, or whatever). It should calculate both boxes when opening the file.

Can somebody help?


Marian Szabo


2 Answers

Voted Best Answer

Enter the following document level script:

this.getField("TodaysDate").value=util.printd("mm/dd/yyyy", new Date());

var date= new Date();
date.setDate(date.getDate()+28)
this.getField("NextDate").value=util.printd("mm/dd/yyyy",date);

Change the field names as applicable.

________________________________________________________________________________________________________________ www.PDFAutomationStation.com

IMAGE ALT TEXT IMAGE ALT TEXT IMAGE ALT TEXT

_________________________________________________________________________________________________________________


By David Dagley   

Create a document level script (name it e.g. "DateCalculation") and replace the function stub that is automatically created with the following. This assumes you have to fields, one is called "Today", and the other one "InOneMonth":

var theDate = new Date();
theDate = theDate.setDate(theDate.getDate() + 28);

this.getField("Today").value = util.printd("mm/dd/yyyy", new Date());
this.getField("InOneMonth").value = util.printd("mm/dd/yyyy", theDate);

See the API documentation for util.printd() for more information about how to format the date:

http://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJS_API_AcroJS%2Futil_methods.htm%23TOC_printdbc-3&rhtocid=_6_1_8_78_0_2

A document level script gets executed when the document is opened.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


Karl Heinz Kremer   


Please specify a reason: