Skip to main content
Participant
March 5, 2021
Answered

Calculated Date Field (14+ days from date entered in another field)

  • March 5, 2021
  • 4 replies
  • 14745 views

Fisrt off, I have spent several hours searching and trying different answers but nothing seems to work for this seemingly simple request.

 

I have two form fields, one is a date field (mm/dd/yyyy) the user will select the date for, and the other is a calculated date field that needs to add 14 days (same format) to the date the user selects. 

 

There have been some very complicated formulas I have tried and some very simple ones (Datefield1+14). I would think this could be done as a "Simplified Field Notation", however I cannot seem to find the formula to accomplish this...

This topic has been closed for replies.
Correct answer BarlaeDC

Hi,

 

Just 2 cents on the above answer, I would use a "custom validation script", my reason for this is that a custom validation script is only called when the field changes, whereas a custom calculation script is called when any field changes and in this instance we only need the script to run when the actual value of field changes.

 

Malcolm

4 replies

Participating Frequently
May 15, 2024

Hello, So I use script: 
var date = util.scand("mm/dd/yyyy", event.value);
if(event.value == "")
this.getField("Text20").value = "";
else {
date.setDate(date.getDate() +7);
this.getField("Text20").value = util.printd("mm/dd/yyyy", date);}

to count out a week from a certain date. I have thirteen boxes with this code so that each box will consecutively display the next date that is 7 days out from the box that is in line before it. I am running into an issue after about 6 boxes. The date stops displaying after the sixth box. When I go to clear the starting week, the weeks in the 7th box finally shows up, but only displays the 7th, 8th, and 9th box. When I clear the data from these boxes, the remaining boxes display the correct dates. Im not sure what I can do to fix this. 

Also, would anyone know how to write a script that will display a specific day for a given week. For example: If the original starting week is week ending 5/11/24, could i get boxes to display the dates for monday, tuesday, wednesday, etc in designated boxes? 

Thank you

Participant
March 28, 2024

Hi

how to add this formula in PDF 

=IF(D23="","",(EDATE(D23,1)-1))

Participating Frequently
March 14, 2024

This is very helpful, but I need more help. I am setting up a form that calculates event timelines for promotion benchmarks. A person will type in their event date (i.e. 12/25/2024) and the next field will subtract 90 days to let the person know when their Design Brief is due (i.e. 09/26/2024). The code worked but it is figuring from "Today's Date" rather than the date someone inputs into the form. 

Nesa Nurani
Community Expert
Community Expert
March 14, 2024

Post the script you tried.

Participating Frequently
March 14, 2024

var date = util.scand("mm/dd/yyyy", event.value);
if(event.value == "")
this.getField("Event-Date").value = "";
else {
date.setDate(date.getDate() -90);
this.getField("Event-Date ").value = util.printd("mm/dd/yyyy", date);
}

 

I am assuming "Event-Date" means today's date. I need it to calculate from the date selected by the person filling the form.

Nesa Nurani
Community Expert
Community Expert
March 5, 2021

As "Custom calculation script" of field where you select date use this.

var date = util.scand("mm/dd/yyyy", event.value);
if(event.value == "")
this.getField("Text1").value = "";
else {
date.setDate(date.getDate() +14);
this.getField("Text1").value = util.printd("mm/dd/yyyy", date);}

Change "Text1" to the name of the field where you want to add +14.

Participant
June 19, 2022

If I need two text fields to display, for example, "Text1 for 14 days and Text2 for 30 days, is it possible??

Nesa Nurani
Community Expert
Community Expert
October 20, 2022

I updated the script based on the field names.  Days = the variable field that will have a number entered and Date3 is the the field that has the date that the number of days should be added to.  I am entering the script under custom calculation script and it isn't working.  

 

var nDays = Number(this.getField("Days").valueAsString);
var date = util.scand("mm/dd/yyyy", event.value);
if(event.value == "")
this.getField("Date3").value = "";
else {
date.setDate(date.getDate() +nDays);
this.getField("Date3").value = util.printd("mm/dd/yyyy", date);}


It should work fine, check console for errors.

In what field did you add script?

If you can't figure it out, please share your file with us.