You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

报表表达式累计时长超24小时显示天数问题求助

解决SSRS时长总和显示天数的问题

你的问题根源在于DateAdd("s", SUM(Fields!TotalDowntime.Value), "00:00:00")返回的是基于1900年1月1日的日期,即便总时长为0秒,dd格式也会取该日期的天数1,导致显示01 days。以下是两种实用的解决方法:

方法一:手动计算时分秒并拼接字符串(推荐)

直接计算总秒数对应的天、时、分、秒,按需拼接显示内容,0天自动隐藏天数部分:

=
Dim totalSeconds as Integer = SUM(Fields!TotalDowntime.Value)
Dim days as Integer = totalSeconds \ 86400
Dim hours as Integer = (totalSeconds Mod 86400) \ 3600
Dim minutes as Integer = (totalSeconds Mod 3600) \ 60
Dim seconds as Integer = totalSeconds Mod 60
Dim output as String = ""

If days > 0 Then
    output = days & " days "
End If

output &= hours.ToString("00") & " hrs " & minutes.ToString("00") & " mins " & seconds.ToString("00") & " secs"
Return output

效果示例:

  • 总时长12小时30分 → 12 hrs 30 mins 00 secs
  • 总时长25小时15分 → 1 days 01 hrs 15 mins 00 secs
  • 总时长0秒 → 00 hrs 00 mins 00 secs

方法二:基于DateAdjust调整格式显示

如果习惯用日期函数,可通过判断实际天数,动态切换格式字符串:

=
Dim totalTime As DateTime = DateAdd("s", SUM(Fields!TotalDowntime.Value), "00:00:00")
Dim actualDays As Integer = DateDiff("d", #1900-01-01#, totalTime)

If actualDays > 0 Then
    ' 替换格式中的默认天数为实际计算的天数
    Format(totalTime, "dd 'days' HH 'hrs' mm 'mins' ss 'secs'").Replace("0", actualDays.ToString(), 1, 2)
Else
    ' 0天只显示时分秒
    Format(totalTime, "HH 'hrs' mm 'mins' ss 'secs'")
End If

内容的提问来源于stack exchange,提问作者Saud

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 20:25:48