Skip to main content
Participant
July 16, 2025
Answered

How to calculate the end date if when start date and number of weeks is provided?

  • July 16, 2025
  • 2 replies
  • 179 views

I'm trying to create a form to calculate parental leave weeks.

I have a version where if the employee enters the start and end date, the number of weeks of their leave would be calculated. Can this be reverse-engineered so that the employee enters the number of weeks they want to take, enter their start date, and have the PDF form spit out the end date?

 

This is what I'm working with:

// Get the start and end date values from the form fields
var startDate = this.getField("Start Date 1").value;
var endDate = this.getField("End Date 1").value;

// Convert the date strings to Date objects
var startDateObj = util.scand("dd/mm/yyyy", startDate);
var endDateObj = util.scand("dd/mm/yyyy", endDate);

// Calculate the difference in days
var diffInDays = Math.floor((endDateObj.getTime() - startDateObj.getTime()) / 86400000);

// Calculate the number of weeks
var weeks = Math.ceil(diffInDays / 7);

// Display the result in a text field
event.value = weeks;

Correct answer try67

Multiply the number of weeks by 7, then use the setDate method to add that amount of days to the start date to get the end date.

2 replies

JR Boulay
Community Expert
Community Expert
August 28, 2025

[MOVED TO THE ACROBAT PRO DISCUSSIONS]

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 16, 2025

Multiply the number of weeks by 7, then use the setDate method to add that amount of days to the start date to get the end date.