Skip to main content
Inspiring
August 22, 2022
Question

Error in script code

  • August 22, 2022
  • 0 replies
  • 119 views

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.

This topic has been closed for replies.