Copy link to clipboard
Copied
Good evening,
I need help with the below table. Is there a simple script to total the time in an adobe acrobat form?
Thank you in advance for your help.
Copy link to clipboard
Copied
See these tutorials:
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-2
https://acrobatusers.com/tutorials/working-with-date-and-time-in-acrobat-javascript-part-3
I've also developed a tool that makes exactly this kind of calculation very simple. If you're interested: Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet
Copy link to clipboard
Copied
Got excatly the time sheets at work.
I named my fields that way -> ADM034.TABLE.number.number
numbers are replaced by the y/x position of the cell as if it was a table in excel. The first number being the row (y) and the last number being the column (x). Numbers are 0-based.
ADM034.TABLE.0.0 ADM034.TABLE.0.1 ADM034.TABLE.0.2
ADM034.TABLE.1.0 ADM034.TABLE.1.1 ADM034.TABLE.1.2
ADM034.TABLE.2.0 ADM034.TABLE.2.1 ADM034.TABLE.2.2
etc
Then put the same script in the calculate event of the total field. (You should pass it as a doc level function but you don't have to)
var myName = event.target.name
var aName = myName.split(".")
var myLine = Number(aName[2])
var myColumn = Number(aName[3])
//gather the values
var SstartValue = this.getField("ADM034.TABLE."+myLine+"."+(myColumn-2)).valueAsString
var SstartTime = SstartValue.substr(0, 2)+":"+SstartValue.substr(2)
var SendValue = this.getField("ADM034.TABLE."+myLine+"."+(myColumn-1)).valueAsString
var SendTime = SendValue.substr(0, 2)+":"+SendValue.substr(2)
if ((SstartValue != "")&&(SendValue != "")){
//convert to date object
var OstartTime = util.scand("yyyy-mm-dd HH:mm", "2018-01-01 "+SstartTime)
var OendTime = util.scand("yyyy-mm-dd HH:mm", "2018-01-01 "+SendTime)
//convert to milliseconds
var milStart = OstartTime.valueOf()
var milEnd = OendTime.valueOf()
//End time update
if (milStart > milEnd) milEnd += 1000*60*60*24
event.value = (milEnd-milStart)/(1000*60*60)
}
else event.value = ""