开发者

Convert hours to minutes, SQL Server 2005

开发者 https://www.devze.com 2023-01-24 12:07 出处:网络
How can I find 开发者_运维知识库the difference between this, for example, 1700 hours and 1020 hours.

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'))
0

精彩评论

暂无评论...
验证码 换一张
取 消