How to Display beyond 24 hrs in SSRS 2008 in HH:MM:SS format

与世无争的帅哥 提交于 2019-12-29 09:28:28

问题


I have a report in SSRS 2008 that pulls data from a table with a column, TotalTime that is an Integer value in seconds.

To display is as time I use this in the expression:

=Format(DateAdd("s", Fields!TotalTime.Value, "00:00:00"), "HH:mm:ss")

(got that from here: Display Seconds Count in HH:MM:SS format in SSRS 2008)

Now, when the value goes beyond 24 hrs it does kind of a "module" value. I mean this: if the value would be 29 hrs, instead of displaying 29:00:00 it will display 05:00:00. If the value if 51 hrs, it will display 03:00:00 (takes out 48 hrs).

How do I solve this?

Thanks!


回答1:


There are 86,400 seconds in a day. So just use days if the seconds are greater than that:

=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")



回答2:


For HH:mm:ss format you can use this:

=Floor(Fields!TotalTime.Value / 3600) &":"& Format(DateAdd("s", Fields!TotalTime.Value, "00:00"), "mm:ss")

In this case, for example 90000sec will be displayed as: 25:00:00

For DD:HH:mm:ss format use this:

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

90000sec will be shown as: 1:01:00:00




回答3:


You really need to use the hour based solution, the day based one can potentially get you into trouble with Daylight Savings Time change overs.

=Floor(Fields!TotalTime.Value / 3600) &":"& Format(DateAdd("s", Fields!TotalTime.Value, "00:00"), "mm:ss")


来源:https://stackoverflow.com/questions/13534686/how-to-display-beyond-24-hrs-in-ssrs-2008-in-hhmmss-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!