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..
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";
Change that line to:
var dueMillis = dateStart.getTime() + (Number(this.getField("NumberOfDays").valueAsString) * oneDay);
(change "NumberOfDays" to the actual field name, of course)
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)
Copy link to clipboard
Copied
Nice!! Thank you so much that works!!
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
Copy link to clipboard
Copied
Add 4 days.
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.
Copy link to clipboard
Copied
In the script replace the 5 with 4.