Skip to main content
rosemariem24343617
Participating Frequently
March 31, 2016
Answered

how do i populate a form with current date?

  • March 31, 2016
  • 7 replies
  • 84572 views

I tried the instructions below but it does not work:

In Acrobat:

The script you create to display the current date when the document is opened is a document level script.

To create an automatic date field:1. Select Tools > Forms >. Edit > Add New Field > Text Field and create a text field. (For more infor-mation, see the section on Creating Form Fields in the Acrobat online help.) Select All Properties > General tab and name the field Today.

2. Select the Format tab, chooses Date for the format category, and chooses a month, day, and year format option (for example, “mmm d, yyyy”). On the General tab, make sure the field is read-only because it will be a calculated field, and click Close.

3. To create a document level script that is executed each time the document is opened, choose View > Tools > Document Processing > JavaScript > Document JavaScripts. Name the script Today, and click Add.

4. Delete the automatically generated text, defining a Today function, that is displayed in the script window. Type in the following text in the exact format (line wraps are OK) and click OK.

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

This script binds the Today field to the variable f, and then calculates the value. The newDate() ex-pression creates a new date object initialized to the current date and time. The util object is used to format the date into the month/day/year format.

5. Click OK in the JavaScript Edit dialog box, and then click Close in the JavaScript Functions dialog box.

Correct answer try67

Please see link https://files.acrobat.com/a/preview/9f9e6c73-ad63-4025-bc94-db1f74e44067


The advice you were given above was misleading. You should not have just removed the "var f" part of the code. It broke it. Put it back and if you want to update the field also before the file is printed place it under Tools - JavaScript - Set Document Actions - Document Will Print as well.

The correct code is:

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


Or:

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

7 replies

Precious_enthusiasm16B8
New Participant
November 7, 2017

worked perfectly, thanks!

June 20, 2017

How do you do this in Acrobat Reader DC?

Karl Heinz  Kremer
Community Expert
June 20, 2017

You cannot create forms or edit form field properties in the free Adobe Reader. This can only be done with Adobe Acrobat Pro or Standard.

New Participant
May 12, 2017

Found on this forum - works as a 'Custom calculation script'. 

// get current system date object

var oNow = new Date();

// set value to formatted date string

event.value = util.printd("mm/dd/yyyy", oNow);

Re: How to customize a date field as current day?

rosemariem24343617
Participating Frequently
April 5, 2016

I can only share an image, video and link. There is no option for me to insert a file.

Karl Heinz  Kremer
Community Expert
April 5, 2016

You cannot share a file directly here, you would need to make it available somehow, and then post the link here. The easiest way for you to share a file is using Adobe's Document Cloud service. See here for more information: Share Documents via Adobe's Document Cloud - KHKonsulting LLC

rosemariem24343617
Participating Frequently
April 5, 2016

I'm using Adobe Acrobat DC.

Inspiring
April 3, 2016

If you look closely you will see you are trying to use a different character for the format of the date.

I would set the form field format to "None" or the same format that you are using in the document level script.

This can also be version dependent. I have found consistent formatting for dates is important. It reduces confusion.

Have you opened the Acrobat JavaScript console to see if there are any errors?

The "var f = " is not necessary.

rosemariem24343617
Participating Frequently
April 4, 2016

Thank you gkalserll. I'll try that and let you know.

rosemariem24343617
Participating Frequently
April 5, 2016

Hi gkalserll, I tried your suggestion but it didn't populate current date. Thank you though for your input.

try67
Community Expert
March 31, 2016

"Does not work" is not very helpful... What exactly happened when you tried it?

rosemariem24343617
Participating Frequently
April 4, 2016

It does not populate current date

Inspiring
October 2, 2018

This isn't working for me. I created a text field, named it "Today", created a Document Script and set the field's value per your answer. Nothing happens. I've tried saving the PDF and reopening it to see if that would get things working, but nothing.

I have had Adobe Acrobat Pro DC for about a day now, so I'm definitely fresh. I have version 2019.008.20071. Let me know if you need more info from me, thanks in advance!


You're working with an Adobe Sign form, not a regular Acroform, so the field name isn't what's shown in the Name field of the Properties dialog. You can see the actual name in the fields list in the right-hand pane, but the script won't work when used with Adobe Sign anyway. It will work if you convert to a regular Acroform though.