How can I find 开发者_运维知识库the difference between this, for example, 1700 hours and 1020 hours.
This time is in varchar type. I want to find the exact time difference between this (24 hour format).
Need:
I want to get 1800 - 1715 = 45 mins. How to achieve this?
Answer
select DATEDIFF(mi, convert(datetime,LEFT('1020',2) + ':' + RIGHT('1020',2),8),
convert(datetime,LEFT('1700',2) + ':' + RIGHT('1700',2),8))
The following will return you 400 minutes, then you can calculate hours and minutes like '6 hrs 40 minutes'.
select DATEDIFF(mi, convert(datetime, '10:20'), convert(datetime, '17:00'))
精彩评论