如何求和 sql 中的多个小时:分钟?
How to sum multiple hour : mins in sql?
我需要对这个 varchar 值求和。
time 1 = '13:06'
time 2 = '18:59'
time 3 = '14:49'
我试过了。
SELECT
convert(
char(8),
dateadd(
second,
SUM(
DATEPART(
hh,
(convert(datetime,'12:03',1))
)
*
3600
+
DATEPART(
mi,
(convert(datetime,'13:03',1))
)
*
60
+
DATEPART(
ss,
(convert(datetime,'34:03',1))
)
),
0
),
108
)
As Total
我遇到了错误。
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
只需 select 您需要的时间总和为小时:
CAST(sum(DATEDIFF(MINUTE, 0, time)) / 60 AS VARCHAR(8)) + ':' + FORMAT(sum(DATEDIFF(MINUTE, 0, time)) % 60, 'D2') AS [Totalhour]
我需要对这个 varchar 值求和。
time 1 = '13:06'
time 2 = '18:59'
time 3 = '14:49'
我试过了。
SELECT
convert(
char(8),
dateadd(
second,
SUM(
DATEPART(
hh,
(convert(datetime,'12:03',1))
)
*
3600
+
DATEPART(
mi,
(convert(datetime,'13:03',1))
)
*
60
+
DATEPART(
ss,
(convert(datetime,'34:03',1))
)
),
0
),
108
)
As Total
我遇到了错误。
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
只需 select 您需要的时间总和为小时:
CAST(sum(DATEDIFF(MINUTE, 0, time)) / 60 AS VARCHAR(8)) + ':' + FORMAT(sum(DATEDIFF(MINUTE, 0, time)) % 60, 'D2') AS [Totalhour]