如何转换时间类型50:45:55

时间:2017-02-27 10:39:47

标签: sql tsql datetime time casting

如何转换(在T-SQL中)时间类型40:30:00(hh:mm:ss),以键入40.30(十进制)。

1 个答案:

答案 0 :(得分:0)

如果您想将时间转换为十进制,请尝试以下查询:

DECLARE @Col DATETIME  = '23:30:00'
SELECT cast(datepart(hour, @Col) + datepart(minute, @Col) / 100.00 as 
decimal(5, 2))  

For Larger value :

DECLARE @Col VARCHAR(100) = '40:30:00'
DECLARE @Col1 BIGINT = CAST(REPLACE(@Col,':','') AS BIGINT)
SELECT CONVERT(DECIMAL(12,2),@Col1)