I tested this in MySQL, but I'm sure this method can be adapted to work in DB2:
SELECT (end_time DIV 10000) * 3600 + ((end_time DIV 100) % 100) * 60 + end_time % 100 - (start_time DIV 10000) * 3600 - ((start_time DIV 100) % 100) * 60 - start_time % 100 FROM table1
Result:
3
The way it works is to use integer division and modulo operations to extract the HH MM and SS parts of each timestamp and convert each part into seconds. Then the seconds are added together to form the total number of seconds since midnight for each timestamp. The difference between the two gives transaction time.
Please note that this will not work if the transaction starts before midnight and ends after midnight. You may need to consider whether the day has changed and whether it will fix it. If you do not have a day stored in your database, you can look for the time of the negative transmission and add 24 hours to make them positive, and this should give the correct result (if the transactions do not exceed one day in length, but it is probably unlikely to practice).
My attempt to write this for DB2 (not verified):
SELECT (end_time / 10000) * 3600 + MOD(end_time / 100, 100) * 60 + MOD(end_time, 100) - (start_time / 10000) * 3600 - MOD(start_time / 100, 100) * 60 - MOD(start_time, 100) FROM table1
source share