How to Validate That an End Date Is After a Start Date in PDF Forms
Question details
The user needs a method to ensure that an inputted end date is strictly after the start date in a PDF form.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating a fillable PDF form that requires a valid timeframe between start and end dates.
- Observed behavior
- The system needs to compare both dates, and if the end date is not later than the start date, clear the end-date fields and trigger an alert to notify the user.
Consider redesigning your PDF form to use a single date field for both the Start Date and End Date, as this is much simpler and less error-prone than managing separate fields for the month, day, and year.
Use a Custom Calculation Script for Single Date Fields
Apply a JavaScript calculation to a hidden field to parse standard date fields and compare their values.
By using util.scand, you can convert standard date strings into JavaScript Date objects. Comparing their timestamp values allows you to seamlessly validate the date range.
Open your PDF form editor and ensure you have unified text fields created and formatted as dates for both your 'StartDate' and 'EndDate'.
Create a new text field anywhere on your form and set its display visibility to 'Hidden' in the properties panel. This will run the validation.
Right-click the hidden field, select 'Properties', and navigate to the 'Calculate' tab.
Choose 'Custom calculation script' and enter JavaScript using util.scand to read both date components and compare them.
Write an 'if' statement to check if the start date is greater than or equal to the end date. If true, trigger an app.alert() and reset the 'EndDate' field value to an empty string.
Handle Separate Month, Day, and Year Fields
Combine individual date component fields into a single string before parsing and validating.
Create and Edit Smart PDF Forms with WPS Office
WPS Office provides an intuitive PDF editor equipped to handle interactive form creation. You can seamlessly insert text fields, apply form formatting, and prepare documents that are fully compatible with industry standards without complex coding.
- 1. Open PDF Editor: Launch WPS Office and open your PDF document using the WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive field options.
- 3. Insert Date Fields: Click 'Text Field', place it onto your document, and double-click the field to access its formatting properties and assign standard date formatting.

Frequently Asked Questions
Why use a single date field instead of separate month, day, and year fields?
Single date fields are much simpler to format, parse, and validate using built-in document scripts. This reduces potential user errors and significantly limits the complexity of the custom calculation script needed for validation.
How do I clear the end date field if the validation fails?
Within your JavaScript calculation script, you can use the syntax `this.getField("YourEndDateFieldName").value = "";` inside an if-statement when the condition detects that the start date is later than the end date.
What is util.scand used for in PDF form scripts?
It is a built-in Acrobat JavaScript method used to convert a formatted date string from a form field into a standard Date object, allowing you to accurately and numerically compare the timestamps of two different dates.




