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

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

Community Beginner ,
Jan 14, 2021 Jan 14, 2021

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
2.9K
Translate
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
1 ACCEPTED SOLUTION
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)

View solution in original post

Translate
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 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)

Translate
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

Nice!! Thank you so much that works!! 

Translate
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

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

Translate
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

Add 4 days.

Translate
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

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. 

Translate
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
LATEST

In the script replace the 5 with 4.

Translate
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