Skip to main content
Inspiring
August 20, 2022
Pregunta

Calculation of the number of days between two dates depending on the conditions

  • August 20, 2022
  • 0 respuestas
  • 343 visualizaciones

Hello everybody.

First please excuse my English. It is not my mother language.

I am complete beginner in JavaScript. 

I am creating a form in Adobe Acrobat DC for renting a motorhome. In form I have two textboxes with a dates. The first box for the beginning of the lease named "Zacetek" and the second box for the end of the lease named "Konec".I can calculate how many days are between the start and the end of the lease. I calculate this with custom script:

var strStart = this.getField("Zacetek").value;
var strEnd = this.getField("Konec").value;
if(strStart.length && strEnd.length)
{
  var dateStart = util.scand("dd.mm. yy",strStart);
  var dateEnd = util.scand("dd.mm.yy",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;

But I have a problem because the price is different in different periods of time. We have three time periods:

first called "Nizka sezona" from 01.03 to 30.04. and from 15.10. to 30.11.

second called "Srednja sezona" from 01.05. to 30.06. and from 01.09. to 14.10.

third calld "Visoka sezona" from 01.07. to 31.08.

Therefore , I need to know how many days the rental will last in a particular time period.

I have three textboxes, one for each period. For first period named "dniNs" for second period named "dniSs" and for third period named "dniVs". 

I am asking for help on how to write a script that will calculate how many days are in each time period, between start and end of the lease, and write the value in the corresponding textbox.

I hope that I have clearly described my problem and that someone will be able to help me.

Este tema ha sido cerrado para respuestas.