How to Validate a Date Difference in an Acrobat PDF Form
Question details
The user needs to validate the difference between two dates (such as a signature date and a transportation date) in a PDF form to ensure they fall within a strict 48-hour timeframe.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires automated validation to check if a user's signature date is within 48 hours of a stated transportation date.
- Observed behavior
- A custom Acrobat JavaScript validation script must be correctly implemented to calculate the difference in milliseconds and reject invalid inputs.
Before writing your validation script, verify the exact format of the date fields in your PDF form (e.g., mm/dd/yyyy) to ensure the JavaScript util.scand() function parses the dates correctly.
Implement JavaScript Validation for Date Differences
Use a custom validation script to compare the millisecond values of two date fields and reject inputs that exceed the 48-hour limit.
To validate date differences in an Acrobat form, you must convert the date strings into JavaScript Date objects. Once converted, you can subtract one date from another to calculate the exact difference in milliseconds.
Since 48 hours equals 172,800,000 milliseconds, you can compare the calculated difference against this value. If the difference is greater, set the script to trigger an alert and use event.rc = false to reject the input.
Open your PDF in Form Editing mode and determine the exact field names for both the transportation date and the signature date.
Right-click the signature date field, select 'Properties' from the context menu, and navigate to the 'Validate' tab.
Select the 'Run custom validation script' radio button and click the 'Edit' button. Retrieve the transportation date value using this.getField('TransportationDate').value.
Convert both date field values into JavaScript Date objects using the util.scand('mm/dd/yyyy', dateString) method. Subtract the transportation date from the signature date to calculate the difference in milliseconds.
Write an if statement to check if the difference exceeds 172800000. If it does, display an error message using app.alert('Signature date must be within 48 hours.') and set event.rc = false to reject the input.

Manage and Fill PDF Forms Effortlessly with WPS Office
WPS Office provides a comprehensive, lightweight PDF editor that allows you to seamlessly fill, manage, and edit professional PDF forms. Easily handle forms with date fields and electronic signatures using an intuitive interface.
- 1. Open Your PDF Document: Launch WPS Office and open your PDF document containing the required form fields.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form filling and editing options.
- 3. Fill and Sign: Click directly on the designated date or signature fields to input your data, or use the 'Fill & Sign' feature to quickly add a legally binding signature.
- 4. Save and Export: Click 'File' and select 'Save' to preserve your filled form, or export it as a flattened PDF to lock your dates and signatures securely.

Frequently Asked Questions
Why is my PDF JavaScript date validation not working?
If validation fails without an error, ensure you are using the correct field names, matching the exact date formatting string in the util.scand() function, and applying the script specifically to the Validate event of the field.
How do I calculate the difference between two dates in an Acrobat PDF?
Convert the string values of both date fields into valid Date objects using Acrobat's util.scand() method. Subtract one parsed date from the other to return the difference in milliseconds, which can then be converted to hours or days.
What does event.rc = false do in Acrobat JavaScript?
Setting event.rc = false inside a validation script tells Acrobat to reject the user's current input. The entered value will be blocked, and the field will revert to its previous state.
Can I use standard JavaScript date methods in PDF forms?
Yes. Once a date string is successfully parsed into a standard JavaScript Date object using util.scand(), you can utilize native JavaScript date methods like .getTime() or .getDate() to manipulate the data.




