如何在小时内显示时间超过24小时的SSRS

发布于 2025-01-28 15:23:44 字数 533 浏览 5 评论 0原文

我有一份报告,列显示了24小时累积时间超过的时间。我希望在几个小时内展示它。 我找到了一个解决方案,当时间超过86400秒(一天中的秒数)时,它将显示几天和时间的数量,但我只想在小时内显示时间。

=IIF(Fields!TotalTime.Value < 86400, 
Format(DateAdd("s", Fields!TotalTime.Value, "00:00:00"), "HH:mm:ss"), 
Floor(Fields!TotalTime.Value / 86400) & " days, " & Format(DateAdd("s", Fields!TotalTime.Value, 
"00:00:00"), "HH:mm:ss")

I have a report with a column displaying time cumulatively overshooting 24 hours. I'd like it to be displayed in hours.
I've found a solution that when time exceeds 86400 seconds (number of seconds in a day), it'll display number of days and time but I want only time in hours to be displayed.

=IIF(Fields!TotalTime.Value < 86400, 
Format(DateAdd("s", Fields!TotalTime.Value, "00:00:00"), "HH:mm:ss"), 
Floor(Fields!TotalTime.Value / 86400) & " days, " & Format(DateAdd("s", Fields!TotalTime.Value, 
"00:00:00"), "HH:mm:ss")

Desired outcome

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一刻暧昧 2025-02-04 15:23:44

您只能使用表达式执行此操作,但这种方式可以重复使用一点。.

将以下代码添加到您的报告的自定义代码
向原始作者致歉。

( “ rel =“ nofollow noreferrer”> “在此处输入映像说明”

Public Function SecondsAsHHMMSS(ByVal secs) As String
        Dim h As String =INT(secs/3600)
        Dim m as string
        Dim s as string
        If Len(h) <2 Then
                h = RIGHT(("0" & h), 2)
        End If
        m = RIGHT("0" & INT((secs MOD 3600)/60), 2)
        s = RIGHT("0" & ((secs MOD 3600) MOD 60), 2)

        SecondsAsHHMMSS= h & ":" & m & ":" & s

End Function

此功能将花费几秒钟并转换到HH:MM:SS格式。

现在,我们要做的就是通过每行的累积秒数。

我们可以使用system.timespan为此。

这假设数据库字段是时间数据类型

=Code.SecondsAsHHMMSS(RunningValue(Fields!TimeInOffice.Value.TotalSeconds, SUM, Nothing))

从中间开始锻炼。...

  1. 我们获得timeinoffice字段的值,并且由于它是> Time数据类型我们可以使用tatalseconds属性来获取这次代表的秒数。
  2. 我们获得了这些秒数的运行总和(“无”是范围,如果要限制行组中的范围等,请将行组的名称放在引号中,以代替nothere 关键字)
  3. 新的我们有秒数,我们将其传递给我们的自定义功能,

结果看起来像这样。

You could do this with expressions only but this way is a little bit more reusable..

Add the following code to your Report's custom code
(apologies to the original author who's blog I based this on years ago... I can't find your post)

enter image description here

Public Function SecondsAsHHMMSS(ByVal secs) As String
        Dim h As String =INT(secs/3600)
        Dim m as string
        Dim s as string
        If Len(h) <2 Then
                h = RIGHT(("0" & h), 2)
        End If
        m = RIGHT("0" & INT((secs MOD 3600)/60), 2)
        s = RIGHT("0" & ((secs MOD 3600) MOD 60), 2)

        SecondsAsHHMMSS= h & ":" & m & ":" & s

End Function

This function will take a number of seconds and convert to to HH:MM:SS format.

Now all we have to do is pass in the cumulative number of seconds for each row.

We can use System.TimeSpan for this.

This assumes the database field is a TIME datatype

=Code.SecondsAsHHMMSS(RunningValue(Fields!TimeInOffice.Value.TotalSeconds, SUM, Nothing))

Starting from the middle and working out....

  1. We get the value of the TimeInOffice field and, as it's a Time datatype we can use the TotalSeconds property to get the number of seconds this time represents.
  2. We get the running sum of these number of seconds ('Nothing' is the scope, if you want to limit the scope within a rowgroup etc, put the name of the rowgroup, in quotes, in place of the Nothing keyword)
  3. New we have the number of seconds, we pass this to our custom function

The result looks like this.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文