Copy link to clipboard
Copied
I'm trying to calculate a end date from a start date and number of days to add, both collected via user input. I've read the tutorials relevant and thought I understood how it worked but I can not figure out why my code wont output.
So user enters that the start date is 01/02/03 and it takes 5 days. I need the end date to output 01/07/03. I can't seem to see why it won't.
Here's what I've got:
-------------------------------------------------------------------------------------------------------------------
var startDate = this.getField("startDate_1").value; // get start date string
var endDate = this.getField("endDate_1"); // define the field the end date will be in
if(startDate.value != ""){
var dateConverted = util.scand("mm/dd/yy", startDate); // convert string to date object
var addDays = this.getField("days_1");
var oneDay = 24 * 60 * 60 * 1000;
var addDayMillis = addDays * oneDay;
var endMillis = dateStart.getTime() + addDayMillis;
var calcEndDate = new Date(endMillis);
endDate.value = util.printd("mm d, yy",calcEndDate);
}
else{
endDate.value = "----";
}
-------------------------------------------------------------------------------------------------------------------
What did I miss here?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Where did you define dateStart? Where do you use dateConverted?
Copy link to clipboard
Copied
Hi, did you get this solved?.. I'm trying to do the same thing but have no clue on how to get this work
Copy link to clipboard
Copied
What have you tried?
Copy link to clipboard
Copied
the code up there.. and have this one where I can let a fixed number.. but want to be an input number..
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;
var dueDate = new Date(dueMillis);
event.value = util.printd("mmm d, yyyy",dueDate);
}
else
event.value = "NA";
Copy link to clipboard
Copied
Do you mean that instead of 5 days you want to add a number that comes from a field?
That code seems fine to me. What happened when you used it? Did you check the JS Console for errors?
Copy link to clipboard
Copied
I replied in your other thread: https://community.adobe.com/t5/acrobat/add-x-days-from-input-number-to-calendar-date-and-get-end-dat...

