## Adobe Acrobat Forms : Add a specific number at specific interval

Contributor ,
Sep 16, 2020

Copied

I am trying to add a particular number at regular intervals

I have difference between 2 dates  in hours

so  for first 24 hours  result 1  ,

even more than a minute to 24 hours >> result 1+.5 = 1.5 ,

then again even more than a minute  to next 8 hours  >> result 1.5 + .5 = 2

then again even more than a minute to next 16 hours  >> result 2 + .5 = 2.5

then again even more than a minute to next 8 hours >> result 2.5 + .5 = 3

then again even more than a minute to next 16 hours >. result  3 + .5 = 3.5   and so on.

In short .5 to be added after 24 hours for at every more than 8 hours & 16 hours

I am using the below script  but not able to achieve the above :

var miles = this.getField("minutes").value; //difference between days in minutes

var hrs = Math.floor(miles/(60*24));  //capturing the hours part
var min = miles%60 //capturing the remainder minutes

if(hrs == "0" && min > 0){event.value =1}
else if (hrs >0 && min >0) {event.value = hrs + ".5"}
else if (hrs > 0 && min == "0"){event.value = hrs}

Contributor
| Contributor

Found the correct script after doing lot of permutation and combination.

Below is the script:

``````var miles = this.getField("Diff_Minutes").value; //Difference between 2 dates in Minutes
var nDays = Math.floor(miles/(60*24));  //Capturing the full Days
var rHours = Math.floor(miles/60) - (nDays*24); //Capturing the full hours remaining after full Days
var rMinutes = miles%60; //Capturing remaining minutes after capturing full days & hours

event.value = 0;

if(nDays <= 0 && (rMinutes > 0 || rHours > 0) ){event.value = 1};
if(nDays == "1" && rMinutes == "0" && rHours == "0"){event.value = 1}
if(nDays >=1 && rMinutes == "0" && rHours == "8"){event.value = nDays + .5}
if(nDays >= 1 && rMinutes > 0 && rHours >= 8 ){event.value = nDays + 1};``````

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

145

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

## Adobe Acrobat Forms : Add a specific number at specific interval

Contributor ,
Sep 16, 2020

Copied

I am trying to add a particular number at regular intervals

I have difference between 2 dates  in hours

so  for first 24 hours  result 1  ,

even more than a minute to 24 hours >> result 1+.5 = 1.5 ,

then again even more than a minute  to next 8 hours  >> result 1.5 + .5 = 2

then again even more than a minute to next 16 hours  >> result 2 + .5 = 2.5

then again even more than a minute to next 8 hours >> result 2.5 + .5 = 3

then again even more than a minute to next 16 hours >. result  3 + .5 = 3.5   and so on.

In short .5 to be added after 24 hours for at every more than 8 hours & 16 hours

I am using the below script  but not able to achieve the above :

var miles = this.getField("minutes").value; //difference between days in minutes

var hrs = Math.floor(miles/(60*24));  //capturing the hours part
var min = miles%60 //capturing the remainder minutes

if(hrs == "0" && min > 0){event.value =1}
else if (hrs >0 && min >0) {event.value = hrs + ".5"}
else if (hrs > 0 && min == "0"){event.value = hrs}

Contributor
| Contributor

Found the correct script after doing lot of permutation and combination.

Below is the script:

``````var miles = this.getField("Diff_Minutes").value; //Difference between 2 dates in Minutes
var nDays = Math.floor(miles/(60*24));  //Capturing the full Days
var rHours = Math.floor(miles/60) - (nDays*24); //Capturing the full hours remaining after full Days
var rMinutes = miles%60; //Capturing remaining minutes after capturing full days & hours

event.value = 0;

if(nDays <= 0 && (rMinutes > 0 || rHours > 0) ){event.value = 1};
if(nDays == "1" && rMinutes == "0" && rHours == "0"){event.value = 1}
if(nDays >=1 && rMinutes == "0" && rHours == "8"){event.value = nDays + .5}
if(nDays >= 1 && rMinutes > 0 && rHours >= 8 ){event.value = nDays + 1};``````

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

146

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 16, 2020 0
7 Replies 7
Most Valuable Participant ,
Sep 16, 2020

Copied

Remove the double-quotes around all the numbers.

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 16, 2020 0
Contributor ,
Sep 16, 2020

Copied

same thing.. not working as per requirement even after removing the ""

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 16, 2020 0
Most Valuable Participant ,
Sep 16, 2020

Copied

Either share the file or be more specific about what "not working" means, exactly...

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 16, 2020 0
Contributor ,
Sep 17, 2020

Copied

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 17, 2020 0
Sep 17, 2020

Copied

I can't see any calculation at the field "Result".

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 17, 2020 0
Contributor ,
Sep 17, 2020

Copied

script is already provided in my original post...you can copy it and change the field name

i removed the script from result as to avoid any confusion......you can write script from scratch or edit my script to meet the condition mentioned in the pdf file

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 17, 2020 0
Contributor ,
Sep 18, 2020

Copied

Found the correct script after doing lot of permutation and combination.

Below is the script:

``````var miles = this.getField("Diff_Minutes").value; //Difference between 2 dates in Minutes
var nDays = Math.floor(miles/(60*24));  //Capturing the full Days
var rHours = Math.floor(miles/60) - (nDays*24); //Capturing the full hours remaining after full Days
var rMinutes = miles%60; //Capturing remaining minutes after capturing full days & hours

event.value = 0;

if(nDays <= 0 && (rMinutes > 0 || rHours > 0) ){event.value = 1};
if(nDays == "1" && rMinutes == "0" && rHours == "0"){event.value = 1}
if(nDays >=1 && rMinutes == "0" && rHours == "8"){event.value = nDays + .5}
if(nDays >= 1 && rMinutes > 0 && rHours >= 8 ){event.value = nDays + 1};``````

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 18, 2020 0