PDF Editing Issues

How to Get the Day of the Week from a PDF Date Field

Maira MehtabMaira Mehtab Nov 2, 2026 869 views

Question details

The user needs to retrieve the specific day of the week from an Acrobat date field using JavaScript.

Extracting the Day of the Week from a PDF Date Field via JavaScript
Product
Adobe Acrobat / PDF Forms
Device & OS
not provided
Scenario
Writing a custom script within a PDF form to extract the weekday text from a field that contains a full date.
Observed behavior
When fetching the value from a date field that visually displays an abbreviated weekday, the script returns the full underlying date string instead of just the formatted weekday text.
Before you start

Ensure your PDF editor supports JavaScript for forms and that you have the necessary permissions to edit the document-level scripts or form field properties.

Solution 1Recommended

Use JavaScript to Parse the Date Object and Extract the Weekday

By reading the field's underlying value as a Date object, you can use the standard JavaScript getDay() method to accurately determine the day of the week regardless of visual formatting.

In PDF forms, visual formatting applied to a date field only changes how the information is displayed on the screen. The actual data stored within the field remains the original date string.

To get the specific day of the week, you must retrieve that underlying string, convert it into a standard JavaScript Date object, and utilize the built-in Date methods.

1
Access Field Properties

Open your PDF in form editing mode, right-click the target field where you want the weekday to appear, and select 'Properties' to add a custom calculation script.

2
Retrieve the Date Value

In your JavaScript editor, get the value of the date field by writing: var dateString = this.getField('YourDateFieldName').valueAsString;

3
Create a Date Object

Convert the retrieved string into a JavaScript Date object by using: var d = new Date(dateString);

4
Extract the Weekday

Call the getDay() method on your Date object using: var dayNum = d.getDay(); This will return an integer between 0 (Sunday) and 6 (Saturday).

5
Convert Number to Text

To display the actual text, create an array of days (e.g., var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];) and retrieve the name using days[dayNum].

Use JavaScript to Parse the Date Object and Extract the Weekday
Standard JavaScript Support: PDF forms rely on standard JavaScript core objects, so you can refer to extensive online resources like MDN Web Docs for advanced Date object manipulations.
Advanced PDF Form Editing

Manage Interactive PDF Forms Seamlessly with WPS Office

If you are looking for a highly capable and user-friendly tool to handle PDF documents, WPS Office provides comprehensive PDF editing and form management features to streamline your workflow.

  1. 1. Open WPS PDF: Launch WPS Office and click on the 'PDF' module from the main dashboard.
  2. 2. Load Your Document: Open your target PDF file that contains the forms you need to manage.
  3. 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to begin interacting with, filling, or modifying form fields.
  4. 4. Save and Export: Once your data is entered, click 'Save' or use the export tools to share your finalized interactive document.
Effortlessly create, edit, and fill interactive PDF formsFully compatible with standard PDF formats and Adobe form structuresLightweight and fast application with an intuitive interfaceBuilt-in tools to convert PDFs to Word, Excel, and other Office formats seamlessly
microsoft office alternative - wps office

Frequently Asked Questions

Why does my date field only show the abbreviation but output the full date in scripts?

The visual formatting applied to a PDF form field only changes how the data is displayed to the user. The underlying value stored in the document remains the complete, unformatted date string.

What values does the JavaScript getDay() method return?

The getDay() method returns an integer between 0 and 6 representing the day of the week, where 0 is Sunday, 1 is Monday, and so on up to 6 for Saturday.

How can I make the script return 'Monday' instead of '1'?

You can define an array containing the days of the week in your script, such as ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']. Then, use the integer returned by getDay() as the index to pull the corresponding string from the array.