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

how do i populate a form with current date?

Community Beginner ,
Mar 31, 2016 Mar 31, 2016

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript

Views

78.7K

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

Community Expert , Apr 05, 2016 Apr 05, 2016

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

Votes

Translate

Translate
Community Expert ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

Try setting the value property 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
LEGEND ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

LATEST

I'm not aware of a way to do that. The date picker has a mind of its own and it doesn't look like you can change 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
Community Expert ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

I believe it does that by default when you click the empty field. Is that not the case?

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 ,
Jan 07, 2019 Jan 07, 2019

Copy link to clipboard

Copied

No, it's empty at first. I want current date as default in date picker.

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 ,
Apr 03, 2016 Apr 03, 2016

Copy link to clipboard

Copied

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.

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 ,
Apr 04, 2016 Apr 04, 2016

Copy link to clipboard

Copied

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

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 ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

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

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 ,
May 13, 2017 May 13, 2017

Copy link to clipboard

Copied

Autodate​ is a sample working form located on Dropbox that works and shows how the auto date field will not reset upon a form reset.

Note the use must be using a program, app, or web browser that can support JavaScript's date object, date formatting, document level scripts, etc.

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 ,
Jan 16, 2018 Jan 16, 2018

Copy link to clipboard

Copied

can you help me set up an automated date form that will automatically fill it with the date 5 days from the current day?

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 ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

This question has been asked and answered many many times. Have you searched the forum for "adding days"?

Acrobat forms use JavaScript and you will use the Date object that has may properties and methods that can be used to manipulate the date, like getDate() and setDate() . These methods can be used to get the date of the month from the date object and then one can adjust that value as needed and then the adjusted value can be used to set the date object to that 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
New Here ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

i am a noob when it comes to coding. can you please give me the exact code for this to work? this would be so much help ! thank you!

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 ,
Jan 18, 2018 Jan 18, 2018

Copy link to clipboard

Copied

Here is a tutorial that provides the code, and an example document

https://acrobatusers.com/tutorials/date_time_part1

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

I'm using Adobe Acrobat DC.

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 ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

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

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 ,
Apr 05, 2016 Apr 05, 2016

Copy link to clipboard

Copied

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

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 ,
May 12, 2017 May 12, 2017

Copy link to clipboard

Copied

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?

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
Guest
Jun 20, 2017 Jun 20, 2017

Copy link to clipboard

Copied

How do you do this in Acrobat Reader DC?

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 ,
Jun 20, 2017 Jun 20, 2017

Copy link to clipboard

Copied

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.

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 ,
Nov 07, 2017 Nov 07, 2017

Copy link to clipboard

Copied

worked perfectly, thanks!

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