Format a User-Selected Date with Ordinal Suffixes in Adobe Acrobat
Question details
Format a date entered in an Acrobat form with the correct ordinal suffix, such as 4th of February 2022.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A form user enters a date, and the form displays it as a day with an ordinal suffix followed by the month and year.
- Observed behavior
- The suffix should be calculated from the entered date, not from the current date.
Open the PDF in an Acrobat version that can edit form fields, and decide which numeric date format users will enter, such as d/m/yyyy. Make sure JavaScript is enabled in Acrobat or Reader when testing the form.
Add a custom validation script to the Acrobat date field
Use this script to calculate the suffix from the date entered by the user.
The script treats 11, 12, and 13 as exceptions and gives them the suffix th. It does not use the computer's current date.
In Acrobat, open the PDF and select All tools > Prepare a form. Double-click the date field to open its properties.
On the Format tab, select None so a built-in date format does not overwrite the script's text output.
On the Validate tab, select Run custom validation script, click Edit, and paste this script: if (event.value) { var oDate = util.scand("d/m/yyyy", event.value); if (oDate != null) { var day = oDate.getDate(); var suffix; if (day == 11 || day == 12 || day == 13) suffix = "th"; else if (day % 10 == 1) suffix = "st"; else if (day % 10 == 2) suffix = "nd"; else if (day % 10 == 3) suffix = "rd"; else suffix = "th"; event.value = day + suffix + util.printd(" of mmmm yyyy", oDate); } }
Close the field properties, preview the form, enter 4/2/2022, and move out of the field. The displayed result should be 4th of February 2022. Also test dates such as 11/2/2022 and 21/2/2022.

Work with PDFs and Office documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Microsoft Office files. Its format compatibility helps make migration straightforward. The Acrobat-specific JavaScript solution above should be configured and tested in Acrobat.

Frequently Asked Questions
Why is the script using the wrong date?
A script that calls new Date() uses the current date. Use util.scand() on event.value instead to parse the date entered in the form field.
How do I change the expected date input format?
In the field's Validate tab, edit the custom script and change the mask in util.scand(), for example from d/m/yyyy to m/d/yyyy. Tell users which format to enter.
How does the script handle 11th, 12th, and 13th?
It checks those three days first and assigns th before checking the final digit. This prevents results such as 11st or 12nd.
Why doesn't the formatted date appear when I test the form?
Check that JavaScript is enabled, the script is on the field's Validate tab, and the entered date matches the util.scand() mask. On the Format tab, select None to avoid conflicting built-in formatting.




