Extract Day, Month, and Year From a PDF Date Field
Question details
A form creator needs to automatically populate separate footer fields with the day, month, and year using values selected from a primary date picker field.

- Product
- Device & OS
- not provided
- Scenario
- Designing a dynamic PDF form where a user inputs a date once, and its components are automatically distributed into separate 'dd', 'mm', and 'yyyy' fields.
- Observed behavior
- The user wants to split a single date entry into three distinct text fields automatically rather than requiring the user to type the date multiple times.
Ensure your PDF editing software supports JavaScript for interactive form fields. You will need to know the exact field name of your primary date picker to reference it in the calculation script.
Use Custom JavaScript to Format Date Components
Apply a custom calculation script to each of your target fields (Day, Month, and Year) to extract and format the data from the main date field.
Standard PDF form fields cannot automatically split date strings by default. To achieve this, you must use Adobe's JavaScript API, specifically the util.printd() function, which formats date objects into specific string representations like days or months.
Right-click the destination field (for example, the 'Day' text field) and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab to set up automatic field updates.
Select the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript editor.
Enter a script that retrieves the main date value and formats it. Use a script similar to: var d = this.getField("MainDateField").value; if(d) { var dateObj = util.scand("mm/dd/yyyy", d); event.value = util.printd("dd", dateObj); } else { event.value = ""; }
Perform the same steps for the month and year destination fields. Change the format string in util.printd to "mm" for the month and "yyyy" for the year.

Edit and Manage PDF Forms Easily with WPS Office
WPS Office features a robust PDF editor that allows you to view, fill, edit, and manage interactive PDF forms effortlessly. Whether you are dealing with complex text fields or simple dropdowns, WPS PDF handles it all.
- 1. Launch WPS PDF: Open WPS Office and click on the 'PDF' tab on the home screen to launch the PDF editor.
- 2. Open Your PDF Form: Click 'Open' and select the interactive PDF form you need to fill or edit.
- 3. Access Form Tools: Navigate to the 'Form' or 'Fill & Sign' tab on the top ribbon to access form editing and management tools.
- 4. Save Changes: Fill in the required date fields and form data, then click 'Save' to retain your changes.

Frequently Asked Questions
What is the correct JavaScript function to format dates in a PDF?
In PDF JavaScript, the util.printd(format, dateObject) function is used to format a date object into a string. You can pass format strings like 'yyyy', 'mm', or 'dd' to extract specific parts of the date.
Why isn't my target field updating when I change the main date?
This is usually caused by an incorrect field calculation order. The main date field must be validated or calculated before the destination fields (Day, Month, Year) execute their custom calculation scripts. Check your form's calculation order in the form editing menu.
Can I extract the date components without using JavaScript?
No, standard PDF form fields do not have built-in properties to split date strings. You must use a custom calculation script to parse the date and distribute it to separate fields.
How do I convert the string from the date picker into a date object?
You can use the util.scand(format, dateString) function. It reads the string from your main date field according to the format you specify (e.g., 'mm/dd/yyyy') and converts it into a date object that util.printd() can process.




