Create a PDF Date Field With Current Date in DD/MM/YYYY Format
Question details
The user wants to configure a PDF form field to automatically populate with the current date in a specific format (DD/MM/YYYY) upon clicking.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where users need to quickly input today's date without manually typing it out.
- Observed behavior
- The user needs a JavaScript solution to capture the current date and format it strictly as day, month, and year, without the timestamp.
Ensure you have a PDF editing tool that supports interactive form fields and JavaScript actions, such as Adobe Acrobat Pro or WPS Office PDF Editor.
Use JavaScript to Auto-Fill the Current Date on Click
Add a Mouse Up event script to the PDF text field to automatically fetch and format the current date.
Interactive PDF forms support JavaScript to automate data entry. By binding a simple script to the 'Mouse Up' trigger, the text field will instantly populate with the exact current date whenever a user clicks on it.
Open your PDF document in your PDF editor's form editing mode and create a new text field (or select an existing one where the date should appear).
Right-click the text field and select "Properties" from the context menu to open the Text Field Properties dialog box.
Click on the "Actions" tab at the top of the Properties dialog box.
Choose "Mouse Up" from the Select Trigger dropdown menu. Then, choose "Run a JavaScript" from the Select Action dropdown menu and click the "Add" button.
In the JavaScript Editor window that appears, enter the following code: event.target.value = util.printd("dd/mm/yyyy", new Date());
Click "OK" to save the script, then click "Close" to exit the properties window. Switch to the hand tool or preview mode and click the field to ensure the date populates correctly.

Create and Edit PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to create interactive forms, add text fields, and manage document properties seamlessly.
- 1. Download WPS Office: Download and launch WPS Office, then open your PDF document in the application.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form creation tools.
- 3. Add and Configure Fields: Click 'Text Field' to insert a box, right-click to open its properties, and configure your desired actions or formatting.
- 4. Save the Interactive PDF: Save your newly customized interactive PDF document to share it with your clients or team.

Frequently Asked Questions
Can I set a PDF date field to format as MM/DD/YYYY instead?
Yes. Simply modify the JavaScript code to event.target.value = util.printd("mm/dd/yyyy", new Date());. The util.printd function in PDF JavaScript accepts various standard date formatting patterns.
Why isn't the date updating when I click the field?
Ensure that JavaScript is enabled in your PDF viewer's preferences. If you are using a basic PDF reader or a web browser preview, JavaScript actions on form fields might not be supported. Use a dedicated PDF editor to test the functionality.
How do I prevent users from typing an incorrect date manually?
You can add form validation scripts to ensure manually entered dates match your required format. Alternatively, setting the field to 'Read Only' prevents manual typing, but depending on the PDF viewer, it may also prevent the 'Mouse Up' click event from triggering. Testing in your target PDF viewer is recommended.
Does this JavaScript add the time to the field as well?
No, the script util.printd("dd/mm/yyyy", new Date()) explicitly formats the output to only show the day, month, and year. The time data retrieved by the new Date() function is safely ignored by the formatting string.




