Skip to main content
Known Participant
February 7, 2024
Answered

Form field calculation - adding 2 weeks from today's date

  • February 7, 2024
  • 1 reply
  • 1428 views

Hi there,
I'm looking to create a field that will autopopulate a date that is two weeks out from today's date. I've already created a field that autopopulates today's date.
In my form, the today's date field is named "Today", and the field that I require assistance with is named "Start Date". In other words, I would like the form's start date to always be 2 weeks from today's date.
Any support would be greatly appreciated!
Thanks 🙂

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

As 'Validate' script of "Today" field, use this: (set date format to whatever you need)

if (event.value == "")
 this.getField("Start Date").value = "";
else{
 var today = util.scand("mm/dd/yyyy", event.value);
 var startDate = new Date(today);
 startDate.setDate(today.getDate() + 14);
 this.getField("Start Date").value = util.printd("mm/dd/yyyy", startDate);}

1 reply

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

As 'Validate' script of "Today" field, use this: (set date format to whatever you need)

if (event.value == "")
 this.getField("Start Date").value = "";
else{
 var today = util.scand("mm/dd/yyyy", event.value);
 var startDate = new Date(today);
 startDate.setDate(today.getDate() + 14);
 this.getField("Start Date").value = util.printd("mm/dd/yyyy", startDate);}
jordanm14Author
Known Participant
February 7, 2024

Hi Nesa,

 

Thanks for the quick response! I added your suggested script to the 'properties' > 'validate' tab of the 'today' field, however the Start Date field is still not auto populating a date. Any ideas why this might be happening? Thanks!

 

jordanm14Author
Known Participant
February 8, 2024

It now seems to be working. Thanks again for your help!