How to Calculate ISO 8601 Week Numbers in Acrobat PDF Forms
Question details
The user needs a way to accurately calculate ISO 8601 week numbers for a specific date field within a PDF form using JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Formatting and processing date fields inside a PDF form using custom calculation scripts.
- Observed behavior
- The current script incorrectly assumes weeks start on Sunday and returns week 0 for dates near the start of the year, such as January 1, 1982.
Before modifying the form's script, ensure you have access to the PDF in preparation or editing mode, and verify that the target date fields are configured to receive dates in the d/m/yyyy format.
Update the PDF Form JavaScript for ISO 8601 Compliance
Modify the custom calculation script using the util.scand function to handle ISO 8601 rules accurately, ensuring the week starts on Monday and year transitions are assigned correctly.
The ISO 8601 standard mandates that weeks start on Monday, and the first week of the year is the one containing the first Thursday. Built-in JavaScript date functions often default to a Sunday-based week, meaning strict ISO compliance requires a custom calculation script.
Open the PDF document, enter form editing mode (such as 'Prepare Form'), right-click the date field you wish to modify, and select 'Properties'.
Navigate to the 'Calculate' tab in the Properties dialog box and select the 'Custom calculation script' option.
In your JavaScript code, use the function util.scand("d/m/yyyy", dateString) to accurately convert the text field value into a readable JavaScript Date object.
Write custom logic that shifts the parsed date to the nearest Thursday, identifies the start of the year for that Thursday, and calculates the elapsed weeks to return the precise ISO 8601 week number.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office includes a highly capable PDF editor that lets you quickly build interactive forms, format text fields, and apply standard custom calculations without the high cost of alternative software.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in PDF Editor.
- 2. Access the Form Tab: Click on the 'Form' tab located on the top ribbon to enter form editing mode.
- 3. Insert or Edit Form Fields: Add a new text field or double-click an existing field to access its properties menu.
- 4. Configure Properties: Under the properties settings, set up calculation logic or custom date formats according to your document's requirements.

Frequently Asked Questions
Why does my PDF date script return week 0 for early January dates?
Week 0 typically occurs when the script utilizes standard system date functions that do not account for ISO 8601 rules. In ISO 8601, the first week of the year must contain a Thursday, which changes how early January dates are assigned.
What does the util.scand function do in a PDF script?
The util.scand function is a specific method used in PDF JavaScript to parse a text string into a Date object based on a defined format string (like 'd/m/yyyy'), allowing for accurate date arithmetic.
Can I set Monday as the start of the week without custom JavaScript?
By default, basic PDF form properties do not have a simple toggle for ISO 8601 week calculations. Enforcing a Monday start and Thursday year-check requires implementing a custom JavaScript calculation.




