• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

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

Community Beginner ,
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
How to , JavaScript , PDF forms

Views

1.8K

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

Community Expert , 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)

Votes

Translate

Translate
Community Expert ,
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)

Votes

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
Community Beginner ,
Jan 14, 2021 Jan 14, 2021

Copy link to clipboard

Copied

Nice!! Thank you so much that works!! 

Votes

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 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

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

Votes

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
Community Expert ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

Add 4 days.

Votes

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 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

Thanks for your reply Bernd. 

Apologies, I may not have explained my problem well enough. 

The number of days changes. Therefore, the start date and end date are inclusive. 

For example, the start date might be 01 Jan 23, the number of days could be anything from 01-500 - the end date needs to reflect each day as one day counted. 

The current script I am using - as stated in this thread does not count each day was one whole day. 

For example it my start date is 01 Jan, number of days 5, end date is then showing 06 Jan. I need it to show 05 Jan. 

 

What do I need to change to the script for this to occurr? 

Thanks in advance. 

Votes

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
Community Expert ,
Jan 27, 2023 Jan 27, 2023

Copy link to clipboard

Copied

LATEST

In the script replace the 5 with 4.

Votes

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