Copy link to clipboard
Copied
Hi All.
In my PDF form I would like to calculate total hours between two date fields StartDate and EndDate which formatted like m/d/yyyy. And two time fields StartTime and EndTime which formatted like HH:MM. 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) so Total = 7.
For instance:
StartDate | EndDate | StartTime | EndTime | Total |
---|---|---|---|---|
5/10/2017 | 5/10/2017 | 09:00 | 13:00 | 4:00 |
5/10/2017 | 5/11/2017 | 09:00 | 15:30 | 12:30 |
How to solve that problem?
Thanks.
Copy link to clipboard
Copied
I have a free Date library for ACrobat that has a "daysBetween" method that will make that calculation easier.
Link to the library
http://practicalpdf.com/the-practicalpdf-date-library-for-adobe-acrobat/
Link to daysBetween
Copy link to clipboard
Copied
Doesn't it only do date calculations, not time ones?
Copy link to clipboard
Copied
It has elapsed time as well. From there you can get hours.
Copy link to clipboard
Copied
Neat!
On Fri, May 12, 2017 at 11:19 PM, Joel_Geraci <forums_noreply@adobe.com>
Copy link to clipboard
Copied
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.
Thanks.
Copy link to clipboard
Copied
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?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now