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

Explorer ,
Aug 19, 2022 Aug 19, 2022

Copy link to clipboard


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(" yy",strStart);
  var dateEnd = util.scand("",strEnd);
  var diff = dateEnd.getTime() - dateStart.getTime();
  var oneDay = 24 * 60 * 60 * 1000;
  var days = Math.floor(diff/oneDay);
  event.value = days;
  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.

How to , JavaScript , PDF forms







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