Keep an Acrobat Calculated Date Field Blank When the Source Is Empty
Question details
Keep a calculated PDF date field blank when its source date field is empty.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form calculates a date one day after a source date and formats the result as mm/dd/yy.
- Observed behavior
- Clearing the source date can cause the calculated field to display an invalid date such as 01/00/00.
Open the PDF in Acrobat and identify the source and calculated field names in Prepare a Form. The example below uses prodDate as the source field and adds one day.
Check the source field before calculating the date in Acrobat
Use a custom calculation script to clear the result when the source date is empty.
Test the source field's text before creating a Date object. An invalid Date object still exists, so checking the object alone does not reliably detect an empty source.
In Acrobat, open the PDF and select All tools > Prepare a form. Select the calculated date field and open its Properties.
In the field's Properties, open the Calculate tab, select Custom calculation script, and click Edit.
Replace the calculation script with the following, changing prodDate if your source field has a different name: var dateString = this.getField("prodDate").valueAsString; if (dateString == "") { event.value = ""; } else { var date = new Date(dateString); date.setDate(date.getDate() + 1); event.value = util.printd("mm/dd/yy", date); }
Click OK to save the script, close Properties, and save the PDF. Enter a valid source date to check the next-day result, then clear the source field and confirm that the calculated field is blank.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility makes it easier to move existing files into your workflow. Use Acrobat to edit the Acrobat-specific JavaScript calculation described above.

Frequently Asked Questions
Why does the calculated field show 01/00/00 after I clear the source date?
The script may be trying to create and format a Date from an empty string. Check the source field's valueAsString first and set event.value to an empty string when it is blank.
Where do I add the calculation script in Acrobat?
Open All tools > Prepare a form, open the calculated field's Properties, and select Calculate > Custom calculation script > Edit.
What if my source field is not named prodDate?
Replace prodDate in this.getField("prodDate") with the exact source field name shown in Prepare a Form.
Does the script also handle invalid dates entered by users?
No. It handles an empty source field but does not validate nonempty input. Test the source field's date format and add validation if users can enter invalid dates.




