Table DB2
ID HOURS HOURSMINUTES
1000 480.5 30:30:00
I want to get HOURS - HOURSMINUTES
ID HOURS - HOURSMINUTES
1000 450.0
HOURS is float value in HOURS- so 480.5 hours. HOURSMINUTES is string value: 30:30:00 (30hours 30minutes 00 seconds)
How to subtract?
This is my full expression because I am getting values from two tables (I get them in this format but I can not subtract) . I am getting HOURS already as subtraction from two timestamp formats - result is in float. cumulativetime is string value.
select t1.id,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) as HOURS,t2.cumulativetime as HOURSMINUTES
from t1
join t2 on t2.id=t1.id
When I try to insert solution below I am getting an error.
select t1.id,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) as HOURS,t2.cumulativetime as HOURSMINUTES,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2)- cast(substr(t2.cumulativetime, 1, 2) as int) -
(cast(substr(t2.cumulativetime, 4, 2) as int) / 60.0) as diff
from t1
join t2 on t2.id=t1.id
I tried also Kapil version:
select t1.id,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) as HOURS,t2.cumulativetime as HOURSMINUTES,
(dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) - (CAST(substr(t2.cumulativetime , 1, 2) AS float) + CAST(substr(t2.cumulativetime , 4, 2) AS float)/60 + CAST(substr(t2.cumulativetime , 7, 2) AS float)/3600)) as diff
from t1
join t2 on t2.id=t1.id