I want to subtract two datetime values and the output in HH:MM:SS format.
If the difference is more than one day, the days count needs to be added to hours.
I tried to concat the datediff outputs as mentioned below
select concat(datediff(hh, '2019-07-16 04:45:03.000','2019-07-17 19:38:13.000')
,':',
(datediff(mi, '2019-07-16 04:45:03.000','2019-07-17 19:38:13.000') -(datediff(hh, '2019-07-16 04:45:03.000','2019-07-17 19:38:13.000')*60))
,':',
(datediff(ss, '2019-07-16 04:45:03.000','2019-07-17 19:38:13.000')-(datediff(mi, '2019-07-16 04:45:03.000','2019-07-17 19:38:13.000')*60)))
Expected output: 38:53:10
Actual output: 39:-7:10
Can you tell me what mistake I made? Is there a better way to get the required output?