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

Inserting current time and date in a form

Community Beginner ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

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.

TOPICS
PDF forms

Views

36.2K

Translate

Translate

Report

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

correct answers 1 Correct answer

LEGEND , Feb 27, 2012 Feb 27, 2012

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.

Votes

Translate

Translate
LEGEND ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

That's right, but the last one needs to be changed to:

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

Votes

Translate

Translate

Report

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 ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

Also, there must be a dot between the getField()-method and the value-property.

AND, you need to use a comma inside printd, not a semi-colon.

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

Also, there was an additional typo, so the first needs to change to:

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

Note the period just before the "value".

Votes

Translate

Translate

Report

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 ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 16, 2012 Feb 16, 2012

Copy link to clipboard

Copied

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".

Votes

Translate

Translate

Report

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 ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

ok, tried that and here's the error I get:

TypeError: getField ("Date") is null

1: Doc:Will Print

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

That means you do not have a field named "Date". What is the name of the field you're working with? Case matters, so "Date" is not the same as "date", or anything else.

Votes

Translate

Translate

Report

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 ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

Actualy, looking around the web I found another Adobe forum where you answered another person's question about using a check box to populate a text field with the date, which is actually what I really need, as I want to be able to print the form with or without the date and time appearing. Here's the script you posted:

// Mouse up script for check box

{function () {

     // Get a reference to the text field

     var f = getField ("text");

     // Set the value of the text field

     if (event.target.value !== "off") {

          f.value = util.printd("mm/dd/yyy", newDate ());

          } else {

                f.value = " ";

          }

} ) ();

I copied and pasted the code straight into the mouse up event for the check box, and then changed the text box name to the actuall name of the date text field, and the error I get is "too much recursion".

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

That code does't look like it was correctly copied, or else I made a few mistakes. It should be:

// Mouse up script for check box

(function () {

    // Get a reference to the text field

    var f = getField("text");

    // Set the value of the text field

    if (event.target.value !== "Off") {

        f.value = util.printd("mm/dd/yyy", newDate());

    } else {

        f.value = "";

    }

})();

There would have to be a text field named "text" for this to work.

Votes

Translate

Translate

Report

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 ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 27, 2012 Feb 27, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Feb 28, 2012 Feb 28, 2012

Copy link to clipboard

Copied

Works like a champ for both the date and time fields. Thanks for all your help!

Votes

Translate

Translate

Report

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
New Here ,
Jun 09, 2012 Jun 09, 2012

Copy link to clipboard

Copied

Hello: I'm new to Adobe Foms and I'm using Adobe Pro X.

I'd like to have the current date inserted when the form opens. I inserted the code below in the Document Javascript section of Adobe. When I open the form nothing happens. I'd appreciate any assistance you can give.

function Current_Date()

{getField(Prepared_Date).value=util.printd("mm/dd/yy",new date())

}

Votes

Translate

Translate

Report

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
LEGEND ,
Jun 09, 2012 Jun 09, 2012

Copy link to clipboard

Copied

It should not be a function, so the code can be just:

getField("Prepared_Date").value = util.printd("mm/dd/yy", new Date());

Note the other corrections as well.

Votes

Translate

Translate

Report

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
New Here ,
Jun 09, 2012 Jun 09, 2012

Copy link to clipboard

Copied

Thanks George, that did it.

Votes

Translate

Translate

Report

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
New Here ,
Aug 05, 2020 Aug 05, 2020

Copy link to clipboard

Copied

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)

 

Votes

Translate

Translate

Report

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 ,
Aug 05, 2020 Aug 05, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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