只显示小时和分钟?

时间:2017-04-07 16:21:20

标签: sql sql-server

如果单独显示,则如何在字段中仅显示小时和分钟

OnTriggetExit

Time

3 个答案:

答案 0 :(得分:2)

如果您只想在结果中将hrs和mns连接在一起,请将它们连接起来:

awk '{ if ($2 == COLOR) {print $1, "NA"} else {COLOR=$2; print $1, $2 } }'

答案 1 :(得分:0)

我认为你想要这样的东西。

DECLARE @D1 DATETIME = '20170401'
DECLARE @D2 DATETIME = '20170402 00:05:00'

SELECT RIGHT( '00' + CAST(DATEDIFF(MINUTE, @D1, @D2) /60 AS VARCHAR(2)) , 2) + ':' + RIGHT( '00' + CAST(DATEDIFF(MINUTE, @D1, @D2) % 60 AS VARCHAR(2)) , 2)

-- 24:05

答案 2 :(得分:0)

    SELECT 
    D.numOperador,
    SUM(DATEDIFF(MINUTE, D.FechaSalida, D.FechaLlegada)) / 60 AS [Horas] ,
    SUM(DATEDIFF(MINUTE, D.FechaSalida, D.FechaLlegada)) % 60 AS [Minutos]

    CONVERT(VARCHAR(10),CAST(CAST (D.FechaSalida AS FLOAT) - CAST (D.FechaLlegada AS FLOAT) / 86400. AS DATETIME),108) --86400 equal 1 day

    FROM 
    trkOperadores O     INNER JOIN trfDespacho D 
    ON O.NumOperador = D.numOperador
WHERE 
    O.cveTipoOperador = 2 
    AND O.NumOperador = 900200 
    AND D.FechaSalida>='2017-03-10 00:00:00.000' AND D.FechaLlegada<='2017-03-11 00:00:00.000'
GROUP BY 
    D.NumOperador;
GO