How to Leave a PDF Date Calculation Blank When Start Date is Empty
Question details
The user needs to prevent a PDF calculated date field from showing a calculated date when the source "StartDate" field is left empty.

- Product
- Device & OS
- not provided
- Scenario
- Creating or editing a fillable PDF form with automatic date calculations based on a start date input.
- Observed behavior
- When the StartDate field is empty, the calculation interprets it as the current system date, incorrectly populating the target field with a future date (e.g., 7 days from today).
Ensure you are using a PDF editor that supports custom JavaScript for form fields, and verify the exact field name of your start date input matches the script.
Add a Custom JavaScript Calculation to Check for Empty Fields
Implement a conditional JavaScript statement that checks if the start date is empty before executing the date addition logic.
By default, standard PDF editors may treat an empty date string as the current system date during parsing. By explicitly checking if the field's value is an empty string, we can force the calculated field to remain blank.
The script provided checks the field named 'StartDate'. If it contains a value, the script adds 7 days to it and formats the output; otherwise, it leaves the field blank.
In your PDF form editor, right-click on the target calculation field (the one that should display the result) and select "Properties".
Click on the "Calculate" tab at the top of the Properties window to access the calculation settings.
Select the "Custom calculation script" option and click the "Edit" button. Paste the following code: var startDateString = this.getField("StartDate").valueAsString; if (startDateString == "") { event.value = ""; } else { var startDate = util.scand("mm/dd/yyyy", startDateString); startDate.setDate(startDate.getDate() + 7); event.value = util.printd("mm/dd/yyyy", startDate); }
Click "OK" to save the script, then close the Properties window. Test the form by leaving the "StartDate" empty and verifying that the target field remains blank.

Create and Calculate PDF Forms Seamlessly with WPS Office
WPS Office provides a robust PDF editor that supports advanced form field editing, including interactive text fields, checkboxes, and JavaScript-based custom calculations to automate your document workflows perfectly.
- 1. Open the PDF in WPS Office: Launch WPS Office and open your interactive PDF document using the WPS PDF tool.
- 2. Access the Form tab: Go to the "Form" tab on the top ribbon to enter the form editing mode.
- 3. Edit field properties: Double-click the target date field to open its Properties dialog box.
- 4. Apply the calculation script: Switch to the "Calculate" tab, choose the custom script option, paste your JavaScript logic, and apply the changes.

Frequently Asked Questions
Why does my PDF date calculation show today's date when the field is empty?
When a PDF JavaScript engine uses functions like util.scand() on an empty string, it often falls back to the current system date. Adding an "if" statement to check for an empty string prevents this fallback.
Can I change the date format in the custom calculation script?
Yes. In the script, find the "mm/dd/yyyy" string in both the util.scand and util.printd functions and change it to your preferred format, such as "dd/mm/yyyy" or "yyyy-mm-dd".
How do I calculate a different number of days instead of 7?
Locate the line `startDate.setDate(startDate.getDate() + 7);` in the script. Change the number 7 to whatever number of days you need to add to the start date.
What if my start date field is named differently?
You must update the script to match your field name. Change the "StartDate" part in `this.getField("StartDate")` to the exact name of your field, matching the casing exactly.




