SSRS Format calculated timespan in dd:hh:mm:ss

不羁的心 提交于 2019-12-12 05:19:53

问题


I have a report and one of the fields calculates a timespan in an expression e.g

=Fields!Date1.Value-Fields!Date2.Value

I would like to display in the format dd:hh:mm:ss so days,hours,minutes and seconds. If i just leave the expression it sort of works but i get milliseconds which i don't want and if there are no days then that value disappears.

I've seen lots of examples using formatting to get HH:mm:ss but not on how to do the days.


回答1:


Try:

=Floor(DateDiff("s",Fields!Date1.Value,Fields!Date2.Value) / 86400) & ":" & 
Format(DateAdd("s", Fields!Date1.Value-Fields!Date2.Value, "00:00:00"), "HH:mm:ss")

It will give you dd:HH:mm:ss format. Note Date1 must be greater than Date2.




回答2:


Based on @alejandro's answer I ended up with

=Format(Floor(DateDiff("s",Fields!Date1.Value,Fields!Date2.Value)/86400),"00") 
& ":" & Format(DateAdd("s", (Fields!Date2.Value-Fields!Date1.Value).TotalSeconds, 
"00:00:00"), "HH:mm:ss")

just doing the straight subtraction didn't seem to work.



来源:https://stackoverflow.com/questions/35461898/ssrs-format-calculated-timespan-in-ddhhmmss

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