tags:

views:

42

answers:

1

Someone does 20 Hours 42 Minutes & 16 Seconds in one shift totaling 74536 seconds. How do I get the hours from number of seconds the person has done for that shift?

20 * 60 * 60      =    72000
     42 * 60      =     2520
          16      =       16
                  +    -----
Total             =    74536
____________________________
Total % 60        =  Seconds (16)
Total % ?         =  Minutes (42)
Total % ?         =    Hours (20)

Tried 84600 already; turns out when a number is lower the modulus, it really is not very helpful, and something I am going to have to catch should someone only sign in for a few seconds ...

+1  A: 

You need to use both modulus and division:

t = seconds_in_shift;
secs = t % 60;
t /= 60;
mins = t % 60;
t /= 60;
hour = t;

Or:

secs =  ttime % 60;
mins = (ttime / 60) % 60;
hour =  ttime / 3600;
Jonathan Leffler
And then just floor the results, or cast to int.
Mark Tomlin