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

Calculate end date from start date and number days to add

New Here ,
Jun 13, 2017 Jun 13, 2017

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?

TOPICS
PDF forms

Views

1.2K

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

Votes

Translate

Translate
Community Expert ,
Jun 13, 2017 Jun 13, 2017

Copy link to clipboard

Copied

Where did you define dateStart? Where do you use dateConverted?

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 13, 2021 Jan 13, 2021

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

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

Copy link to clipboard

Copied

What have you tried?

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

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

 

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

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?

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

Copy link to clipboard

Copied

LATEST

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