Skip to main content
Participant
February 23, 2024
Answered

How to Auto Populate a Date Two Weeks From A Set Start Date

  • February 23, 2024
  • 1 reply
  • 1258 views

Hello,

 

I am currently trying to create a pdf that requires a few date boxes.  I have a date box that automatically populates with the date when someone opens the form, but I need to make another box that calculates the date 2 weeks from the first date entered and then auto populate it onto the form.  I have tried several versions of code and cannot seem to get any of them to work for me.  Below is what I have been using and it doesn't come back with any errors but nothing actually auto populates on the pdf form when it opens so the script doesn't seem to be working.  Please advise!

 

var startDate = this.getField("Today").value;

// Convert start date string to a Date object
var startDateObj = util.scand("mm/dd/yyyy", startDate);

// Calculate future date by adding 14 days
var futureDateObj = new Date(startDateObj.getTime());
futureDateObj.setDate(futureDateObj.getDate() + 14);

// Format future date as "YYYY-MM-DD" string
var futureDateString = util.printd("mm/dd/yyyy", futureDateObj);

This topic has been closed for replies.
Correct answer Nesa Nurani

You didn't set the result to show in a field.

Use this as custom calculation script in a field where you want to show new date:

var startDate = this.getField("Today").value;
var startDateObj = util.scand("mm/dd/yyyy", startDate);

if(startDate == "")
event.value = "";
else{
var futureDateObj = new Date(startDateObj.getTime());
futureDateObj.setDate(futureDateObj.getDate() + 14);
var futureDateString = util.printd("mm/dd/yyyy", futureDateObj);
event.value = futureDateString;}

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
February 23, 2024

You didn't set the result to show in a field.

Use this as custom calculation script in a field where you want to show new date:

var startDate = this.getField("Today").value;
var startDateObj = util.scand("mm/dd/yyyy", startDate);

if(startDate == "")
event.value = "";
else{
var futureDateObj = new Date(startDateObj.getTime());
futureDateObj.setDate(futureDateObj.getDate() + 14);
var futureDateString = util.printd("mm/dd/yyyy", futureDateObj);
event.value = futureDateString;}
Participant
February 23, 2024

Thank you so much, that worked beautifully!