## Calculating hours worked from a time stamp

45 pts.
Tags:
AS/400
RPG ILE
Hi Everyone

I work for a trucking company and all of the trucks have onboard computers with GPS tracking, recently the company decided to have the local drivers clock in and out on the OBC that way they also have the location of the unit when the driver clocks in or out. My question is they want a report of each driver and the hours worked for each day. I tried using the SUBDUR function for the two time stamps but the result for the hours worked is not exactly correct it can be off by a few tenths of a minute. I tried using the hour  function but will not show over whole hours so I used the minute function and then divide to total minutes by 60 but that is off by tenths sometimes the time is high and others are low. Below are the calculations

D @clkit          S               T

D @clkot          S               T

D @mnswk          S              5  0

D @hrswk          S              5S 3

C     @clkot        subdur    @clkit        @mnswk:*MN

C                   If        @mnswk> 0

C                   Eval      @hrswk = @mnswk / 60

C                   Endif

Is there a better way getting the hours worked

Thanks, Billy

Software/Hardware used:
AS/400 RPGILE

## Answer Wiki

Thanks. We'll let you know when a new response is added.

off in the seconds…but you computed mintuesD @clkit S T

D @clkot S T

D @secswk S 7 0

D @hrswk S 7S 4

C @clkot subdur @clkit @scswk:*S

C If @scswk> 0

C Eval @hrswk = @scsswk / 3660

Phil

## Discuss This Question: 3 Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
• Thanks Phil
45 pointsBadges:
report
• Braz, send me an email .I have a few other things for ya. rkoontz@ceioh.com Thanks
1,810 pointsBadges:
report
• Try something like this:
```
d  total_seconds  s              9  0 inz(0)
d  decmial_hours  s              5  2 inz(0)
D  time1          S               t   inz(T'12.00.00')
D  time2          S               t   inz(T'13.38.00')

/Free

total_seconds = %diff(time2 : time1 : *s);
decmial_hours = (total_seconds / 60) / 60;

*INLR = *ON;
RETURN;

/End-Free

```
The variable decmial_hours should now have a value of 1.63. Is this what you are looking for?
5,860 pointsBadges:
report