SQL显示时间小时:仅分钟

时间:2016-06-17 08:39:46

标签: tsql time

我正在使用以下代码将int转换为时间,但结果显示为09:00:00.000000等。

(cast(CAST(t0.U_ProdStartTime / 100 as varchar) + ':' + CAST(t0.U_ProdStartTime % 100 as varchar) 
as time)) 
AS 'Start Time',

(cast(CAST(t0.U_ORC_BE_ProdTime / 100 as varchar) + ':' + CAST(t0.U_ORC_BE_ProdTime % 100 as varchar) 
as time))
AS 'End Time',

我希望它只显示09:00:00?

3 个答案:

答案 0 :(得分:4)

CONVERT(VARCHAR(10), GETDATE(), 108)

答案 1 :(得分:0)

SELECT FORMAT(t0.U_ProdStartTime,'hh:mm') AS StartTime,FORMAT(t0.U_ORC_BE_ProdTime,'hh:mm') AS EndTime 
FROM YourTable AS [to]

或者如果你需要秒,你可以使用

 SELECT FORMAT(t0.U_ProdStartTime,'hh:mm:ss') AS StartTime,FORMAT(t0.U_ORC_BE_ProdTime,'hh:mm:ss') AS EndTime 
 FROM YourTable AS [to]

答案 2 :(得分:0)

这是我所知道的一种方法

declare @t int
set @t=345
select convert(varchar(10),
(cast(CAST(@t / 100 as varchar) + ':' + CAST(@t % 100 as varchar) 
as datetime)) ,108)
AS 'Start Time'

结果

Start Time
----------
03:45:00