Skip to main content
Participating Frequently
February 16, 2012
Answered

Inserting current time and date in a form

  • February 16, 2012
  • 2 replies
  • 38598 views

Feel silly here, but I can't seem to find a way to insert form fields that will display currnet time and date, I see where it can be done for a digital signature, but that's not what I need. This is for a client sign in sheet. I want to know what date and time the form is printed, without having to manually enter that data. Thanks.

Correct answer George_Johnson

right, the field is actually called "Date". copied and pasted straight off what you just posted and the error i get now is 'newDate is not defined'. BTW thanks so much for taking the time to help with this.


There is supposed to be a space between "new" and "Date". If that doesn't fix it, I'll be happy to post a working sample.

2 replies

New Participant
August 5, 2020

Mouse over the date field:

var d = new Date();
var f = this.getField("YourFieldNameHere");
if (f.value!=d.value)
	f.value = util.printd ("dd/mm/yyyy", d)

 

try67
Braniac
August 5, 2020

This question is more than 8 years old, and was already answered. What prompted you to reply to it now?
Also, the code you posted is incorrect. A Date object doesn't have a value property.

Inspiring
February 16, 2012

If you want to set a field to show the date/time whenthe document is opened, you can use the following code in a document-level script:

getField("DATETIME").value = util.printd("mm/dd/yyyy HH:MM:ss"; new Date());

where "DATETIME" is the name of the field.

You can use the same code in the "Document Will Print" event to update it at the time of printing.

For more information on the date format string options, see: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html

TRG622Author
Participating Frequently
February 16, 2012

OK, thanks. And if I wanted to break out the date and time into two seperate fields would that be

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

getField("Time") value = util.printd("HH:MM)"; new Time())

Inspiring
February 16, 2012

so this code would be inserted in the Actions tab in the Properties window of the form field? Thanks again. I'm brand new to Acrobat and this is the very first form I'm creating with it.


No, it should be placed either in a document-level JavaScript (Advanced > Document Processing > Document JavaScript (Acrobat 9), or Tools > JavaScript > Document JavaScript) outside of a funtion definition, or in the initial page's Page Open event.

As mentioned, you can also place it in the "Document WIll Print" event if you want it to update at the time of printing. In Acrobat 9 you'd select "Advanced > Document Processing > Set Document Actions" and in Acrobat 10 you'd select "Tools > JavaScript > Set Document Actions".