PDF Editing Issues

How to Subtract One Year from a Date using Acrobat JavaScript

John WilsonJohn Wilson Nov 10, 2026 869 views

Question details

The user needs to use JavaScript in an Adobe Acrobat PDF form to automatically populate a target field with a date exactly one year earlier than the date entered in a source field.

How to Subtract One Year from a Date using Acrobat JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating or editing a fillable PDF form that requires automated date calculations based on user input.
Observed behavior
The target field needs to dynamically calculate and display a date that is one year prior to the date inputted by the user in the source field.
Before you start

Ensure you have a PDF editing tool that supports form field creation and JavaScript validation, such as Adobe Acrobat Pro. Identify the exact field names for both your source date field and target date field before applying the script.

Solution 1Recommended

Use a Validation Script on the Source Date Field

Add a custom JavaScript validation script to the source field so the target field updates automatically whenever a new date is inputted.

This method uses Acrobat's built-in JavaScript engine to scan the inputted date string, mathematically subtract one year, and print the new date into your designated target field.

1
Open the PDF in form editing mode

Open your PDF document in Adobe Acrobat and select the 'Prepare Form' tool from the right-hand pane.

2
Access the source field properties

Right-click the source date field (where users will type the initial date) and select 'Properties' from the context menu.

3
Navigate to the validation tab

In the Text Field Properties dialog box, click on the 'Validate' tab.

4
Add the custom JavaScript

Select the 'Run custom validation script' option and click the 'Edit' button. Paste the following code, ensuring you replace 'WSD' with your actual target field name: if (event.value == "") this.getField("WSD").value = ""; else { var d = util.scand("mm/dd/yyyy", event.value); d.setFullYear(d.getFullYear() - 1); this.getField("WSD").value = util.printd("mm/dd/yyyy", d); }

5
Save and test the form

Click 'OK' to save the script, close the properties window, and exit form editing mode. Test the script by entering a date like '12/31/2023' into the source field to confirm the target field automatically populates with '12/31/2022'.

Use a Validation Script on the Source Date Field
Date Format Match: Ensure the date format in the script (mm/dd/yyyy) matches the format users are expected to enter. If your region uses dd/mm/yyyy, update both the util.scand and util.printd lines accordingly.
Powerful PDF Editor

Edit and Manage PDF Forms Easily with WPS Office

WPS Office includes a robust PDF editor that allows you to view, fill out, and manage PDF forms seamlessly without needing expensive software. It provides an intuitive interface for all your document needs.

  1. 1. Download and Install WPS Office: Go to the official WPS website, download the free installer, and complete the quick setup process on your device.
  2. 2. Open your PDF document: Launch WPS Office, click on 'Open' in the home screen, and select your PDF form file.
  3. 3. Fill and edit the form: Use the 'PDF Edit' or 'Fill & Sign' tools in the top ribbon to interact with your form fields effortlessly.
Easily view and fill out interactive PDF formsConvert PDFs to Word, Excel, or PowerPoint with high accuracyFully compatible with standard PDF formats and Adobe filesLightweight application with a user-friendly interface
microsoft office alternative - wps office

Frequently Asked Questions

Why is the target field not updating when I enter the date?

This usually happens if the target field name in the JavaScript (e.g., 'WSD') does not perfectly match the actual name of the field in your form. Ensure the field names are case-sensitive and match exactly.

How do I change the date format in the Acrobat JavaScript?

You can change the date format by modifying the parameters in the util.scand and util.printd functions within the script. For example, you can change 'mm/dd/yyyy' to 'dd/mm/yyyy' depending on your regional format requirements.

Can I use a similar script to add days instead of years?

Yes. Instead of using the d.setFullYear() method, you can use d.setDate(d.getDate() + 30); to mathematically add 30 days to the date entered in the source field.