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

New Here ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

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..

Cale84_0-1610666720874.png

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";

 

 

 

TOPICS
Comment review and collaborate PDF, How to, JavaScript, PDF forms

Views

81

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Jan 14, 2021 Jan 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)

Likes

Translate

Translate
Most Valuable Participant ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

Change that line to:

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

 

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

LATEST

Nice!! Thank you so much that works!! 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines