How to calculate the end date if when start date and number of weeks is provided?
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;
