Error in script code

Explorer ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

In my Adobe form I use this code:

 

var strStart = this.getField("Start").value;
var strEnd = this.getField("End").value;
if(strStart.length && strEnd.length)
{
  var dateStart = util.scand("dd.mm.yyyy",strStart);
  var dateEnd = util.scand("dd.mm.yyyy",strEnd);
  var diff = dateEnd.getTime() - dateStart.getTime();
  var oneDay = 24 * 60 * 60 * 1000;
  var days = Math.floor(diff/oneDay);
  event.value = days;
}
else
  event.value = 0;

 

I recently noticed that when I enter a start date of 01.03.2022 and an end date of 30.03.2022, it does not calculate the correct value. It calculates correctly until 27.03.2022, but then on 28.03.2022 it calculates 1 day short. How can I fix the code so that it calculates correctly? Thanks for the help.

TOPICS
How to , JavaScript , PDF forms

Views

2

Likes

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
no replies

Have something to add?

Join the conversation