Skip to main content
April 9, 2017
Question

I have a timesheet where TimeOut - TimeIn - Break = Total Hours. I can get this to work but, I need an if clause for working past midnight. If (TimeOut<TimeIn) +24 or If (TotalHours<0) +24. I do not know JavaScript (obviously).

  • April 9, 2017
  • 1 reply
  • 544 views

I have a timesheet where TimeOut - TimeIn - Break = Total Hours.  I can get this to work but, I need an if clause for working past midnight.  If (TimeOut<TimeIn) +24 or If (TotalHours<0) +24.  I do not know JavaScript (obviously).

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
April 9, 2017

Can you post the code you've used so far?

April 9, 2017

I used the Simplified field notation in the Text Field Properties tab as here:

But it comes back with a negative number:

I have always used Excel and can figure out how to do pretty much anything (self-taught) with spreadsheets but, of course, javascript is different.  I have tried many scripts I have found online but, as I do not really understand the language, am not sure what I am doing wrong. One is:

var result = endMin - startMin;

if (result < 0 ) result = (24*60) + result;

Most are much more intricate and quite lengthy.

Thank you!
try67
Community Expert
Community Expert
April 9, 2017

Yeah, that's not going to work, since these are not regular number fields... You would basically need to convert them into Date objects and then calculate the difference between those variables. This issue was discussed here many times in the past. Try searching the forum for "time calculation" or something like that.

If you're interested in setting it up without having to write any code I've developed a tool that allows you to do it very easily, and it will also handle dates that are on different dates correctly. You can find it here: Custom-made Adobe Scripts: Acrobat -- Calculate Time Differences in a Worksheet