I have a free Date library for ACrobat that has a "daysBetween" method that will make that calculation easier.
Link to the library
Link to daysBetween
Doesn't it only do date calculations, not time ones?
I found code and modified it for my task
var cEnd = this.getField("EndDate").value
var cStart = this.getField("StartDate").value;
if(cEnd != "" & cStart != "")
var oEnd = util.scand("m/d/yyyy", cEnd);
var oStart =util.scand("m/d/yyyy", cStart);
var nEnd = Math.floor(Number(oEnd) / (1000 * 60 * 60));
var nStart = Math.floor(Number(oStart) / (1000 * 60 * 60));
event.value = nEnd - nStart;
My problem now how to calculate:
- If StartDate and EndDate are the same so total hours between = 0.
- If startDate and EndDate are different (5/10/2017 and 5/11/2017) Result = 7.
(5/10/2017 and 5/12/2017) Result = 14
and so on.
It is not clear how one gets a value of 7 when the start and end dates are the same. Does the start and end time have any affect on the result?
The same applies if the start and end date are different. What happens if the dates are more than 2 days different?