How to Add 60 Days to a PDF Date Field Using JavaScript
Question details
The user needs a PDF form to automatically calculate an expiration date exactly 60 days after an issue date is selected, and display it in a separate field.

- Product
- Adobe Acrobat PDF Forms
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF form that requires automatic date calculations based on user input.
- Observed behavior
- The calculated expiration date should appear automatically in the target Expiration Date field once the user inputs the Issue Date.
Ensure that your PDF form already contains both the starting date field (e.g., 'Issue Date') and the destination date field (e.g., 'Expiration Date') with clearly defined field names.
Apply a Custom Validation Script to the Issue Date Field
Add a custom JavaScript code to the properties of your starting date field to automatically calculate and push the future date into the target field.
This method utilizes Acrobat's built-in JavaScript engine. By attaching a validation script to the Issue Date field, the form will automatically read the inputted date, add 60 days to it, and output the new date to the Expiration Date field in your specified format.
Open your PDF form in editing mode. Right-click the 'Issue Date' field and select 'Properties' from the context menu.
Navigate to the 'Validate' tab, select 'Run custom validation script', and click the 'Edit' button.
Paste the following script into the editor: if (event.value == "") { this.getField("Expiration Date").value = ""; } else { var date = util.scand("dd-mmm-yyyy", event.value); date.setDate(date.getDate() + 60); this.getField("Expiration Date").value = util.printd("dd-mmm-yyyy", date); }
Ensure the date format in the script ('dd-mmm-yyyy') matches the format set in your field properties. Confirm that your target field is named exactly 'Expiration Date'.
Click 'OK' to close the JavaScript editor, then close the Properties dialog. Test the calculation by entering a date into the Issue Date field.

Edit and Fill PDF Forms with WPS Office
WPS Office offers a comprehensive PDF toolset, allowing you to easily view, fill, and manage interactive PDF forms without needing heavy or expensive software.
- 1. Open PDF File: Launch WPS Office and open your interactive PDF form.
- 2. Fill Form Fields: Click on the fillable fields to input your data, dates, and text.
- 3. Edit Document Text: Navigate to the 'Edit' tab if you need to modify the underlying PDF text or layout.
- 4. Save and Export: Click 'Save' to preserve your filled form data, or export it securely for sharing.

Frequently Asked Questions
Can I change the date format in the JavaScript code?
Yes, you can modify the 'dd-mmm-yyyy' string in both the util.scand and util.printd functions to match your preferred format, such as 'mm/dd/yyyy' or 'yyyy-mm-dd'.
Why isn't the Expiration Date field updating after I enter the Issue Date?
This typically occurs if the target field name in the script doesn't exactly match the actual field name in your document. Verify that the spelling, capitalization, and spacing of 'Expiration Date' match perfectly. It can also happen if the input date format doesn't match the format specified in the script.
How can I add 30 days instead of 60?
Simply modify the calculation line in the script. Change 'date.setDate(date.getDate() + 60);' to 'date.setDate(date.getDate() + 30);' to calculate a 30-day expiration date.
Do these JavaScript date calculations work on mobile PDF viewers?
Most built-in mobile PDF viewers and browsers do not fully support custom JavaScript calculations. To ensure the scripts run correctly, users should fill out the dynamic form using a desktop PDF editor like Adobe Acrobat or dedicated PDF software.




