PDF Editing Issues

Convert a PDF Form Date from YYYY-MM-DD to MM-DD-YYYY with JavaScript

Algirdas JasaitisAlgirdas Jasaitis Nov 19, 2026 871 views

Question details

Convert a date entered by a script into a PDF form from YYYY-MM-DD to MM-DD-YYYY.

Convert a PDF Form Date from YYYY-MM-DD to MM-DD-YYYY with JavaScript
Product
PDF forms with JavaScript
Device & OS
not provided
Scenario
A script populates a PDF form date field, but the form needs to display the date in month-day-year order.
Observed behavior
Changing the field's built-in date format does not display the scripted value in the required format.
Before you start

Open the form in an editor that supports Acrobat form JavaScript, such as Adobe Acrobat Pro, and identify the script and field that receive the original date. Check that the source value is consistently supplied as YYYY-MM-DD.

Solution 1Recommended

Use a hidden source field and a calculated display field

Use this method when you can edit the form and redirect the existing script to a separate source field.

The source field keeps the original date string, while a calculation script validates its components and writes the rearranged date to a visible field. This relies on a PDF viewer that supports Acrobat form JavaScript.

1
Create the source field

In Adobe Acrobat Pro, open All tools > Prepare a form. Add a text field named DateSource, open its Properties, and set its visibility to Hidden. On the Format tab, select None so the original YYYY-MM-DD string is retained.

2
Create the display field

Add a visible text field named DateDisplay. In its Properties, select None on the Format tab and make the field read-only if users should not edit the calculated result.

3
Add the calculation script

In DateDisplay Properties, open Calculate, select Custom calculation script, and click Edit. Paste this script: (function () { var source = this.getField("DateSource"); var value = source ? String(source.value) : ""; var match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value); event.value = ""; if (!match) return; var year = Number(match[1]); var month = Number(match[2]); var day = Number(match[3]); if (year < 1 || month < 1 || month > 12) return; var leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); var days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; if (day < 1 || day > days[month - 1]) return; event.value = match[2] + "-" + match[3] + "-" + match[1]; }).call(this);

4
Update and test the existing script

Change the existing script's field assignment to write the original date to this.getField("DateSource").value instead of DateDisplay. Save the PDF and test it in Acrobat: 2025-03-09 should display as 03-09-2025, while an invalid date such as 2025-02-30 should leave the display blank.

Use a hidden source field and a calculated display field
Viewer support matters: Some PDF viewers do not run Acrobat form JavaScript. If the display field does not update in Acrobat, check Preferences > Forms and enable automatic field-value calculation.
Free Microsoft Office alternative

Work with PDF forms and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. It supports common Microsoft Office formats for easier migration, but it should not be relied on to run or edit the Acrobat JavaScript calculation described above.

Open and work with PDF documents in the same suite as office filesCompatible with common Microsoft Office formats, including DOCX and XLSXUse a familiar interface when moving from Microsoft OfficeAccess a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't the built-in date format fix the scripted value?

A field's date format may not interpret a scripted YYYY-MM-DD string as intended. Converting the validated components in JavaScript gives the display field an explicit MM-DD-YYYY value.

Can I change the original script instead of adding two fields?

Yes. In the script that assigns the field value, parse and validate the year, month, and day, then assign the components in MM-DD-YYYY order. Set the destination text field's Format to None if another format would alter the result.

What happens if the source date is invalid?

The example calculation leaves DateDisplay blank if the value does not match YYYY-MM-DD or if the month and day do not form a valid calendar date.

Will the calculated date work in every PDF viewer?

No. The viewer must support the Acrobat form JavaScript used by the calculation. Test the saved form in the viewer that recipients will use.