Either you have not explained everything, or you've got a reason not to use your brain? First, decide if you need to result in nanoseconds, or seconds, or minutes, or hours, or whatever. Then, take your first value for seconds and subtract it from your second value for seconds. If you have a negative value, add 60 and subtract 1 from the minutes second value. Repeat for minutes and hours. You wind up with the difference in hours, minutes, and seconds (ignoring the days of course -- but accounting for days does not require a lot more effort, in thinking OR coding, to handle). So why are you not able to develop this algorithm yourself?