Skip to main content
Participating Frequently
Feb 16, 2012 3:40 PM UTC
Answered

Inserting current time and date in a form

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.

George_JohnsonCorrect answer
Inspiring
Feb 27, 2012 10:57 PM UTC

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.

20 replies

Participant
Aug 5, 2020 9:40 AM UTC

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)

 

Translate
try67
Community Expert
Community Expert
Aug 5, 2020 1:54 PM UTC

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.

Translate
Inspiring
Feb 16, 2012 4:01 PM UTC

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

Translate
TRG622Author
Participating Frequently
Feb 16, 2012 4:08 PM UTC

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())

Translate
try67
Community Expert
Community Expert
Feb 16, 2012 4:09 PM UTC

There's no Time object. Use new Date() in both instances.

Translate