Skip to main content
Participant
January 14, 2021
Answered

Add x days from input number to calendar date.. and get end date

  • January 14, 2021
  • 1 reply
  • 2820 views

I had this form fields.. 

One with the date Mar 4, 2021 and I want to add in this case 10 days but I want this be a free input and been able to put any number and at the want automatically get the date, in this case Mar 14, 2021.. and I'm not at all good a JS.. 

 

So I found a code where I cand add a X number but will be just that number.. how can I change that o get to work this formulas.. 

 

Attached a picture with forms and code that need to fix/change..

var strStart = this.getField("DateStart").value;
if(strStart.length)
{
var dateStart = util.scand("mmm d, yyyy",strStart);
var oneDay = 24 * 60 * 60 * 1000;
var dueMillis = dateStart.getTime() + 5 * oneDay;   <--- in this line the +5 are the day added, but

var dueDate = new Date(dueMillis);                                    w ant this be an input number..
event.value = util.printd("mmm d, yyyy",dueDate);
}
else
event.value = "NA";

 

 

 

This topic has been closed for replies.
Correct answer try67

Change that line to:

var dueMillis = dateStart.getTime() + (Number(this.getField("NumberOfDays").valueAsString) * oneDay);

 

(change "NumberOfDays" to the actual field name, of course)

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 14, 2021

Change that line to:

var dueMillis = dateStart.getTime() + (Number(this.getField("NumberOfDays").valueAsString) * oneDay);

 

(change "NumberOfDays" to the actual field name, of course)

Participant
January 27, 2023

Hey, I used this code and it worked. However, I am wishing to include the start date as day one. For example, Start date 01 Jan 23 - Days 5 - End date 05 Jan 23. 

What do I need to add? 

Thanks

Bernd Alheit
Community Expert
Community Expert
January 27, 2023

Add 4 days.