Time difference between two fields in report builder 3.0 SSRS

时间:2018-09-28 17:46:49

标签: sql sql-server tsql ssrs-2012 reportbuilder3.0

I have a field called 'obs hours' which calculates time in HH:MM between StartDateHeader and EndDateHeader and then I have 'carve out' time field which calculates time in HH:MM between StartDateDept and EndDateDept

Now I want to subtract carve out time field from obs hours field

below are the expression used for field obs hours example : total obs hours 46 hh:59 mm)

=DATEDIFF("h",Fields!StartDateHeader.Value,Fields!EndDateHeader.Value) & ":" & DATEDIFF("n",Fields!StartDateHeader.Value,Fields!EndDateHeader.Value) MOD 60

below are the expressions used for carve out field (example 00 hh:10mm)

=DATEDIFF("h",Fields!StartDateDept.Value,Fields!EndDateDept.Value)& ":" & DATEDIFF("n",Fields!StartDateDept.Value,Fields!EndDateDept.Value) MOD 60

I don't want to convert these in to decimal format i just want the answer to be in hh:mm format and my answer should be like (example)

         obs hours : 46:59
  carve out time :    0.10
**Total bill hours : 46.49**

Total bill hours expression is needed please

1 个答案:

答案 0 :(得分:0)

为了简化操作,我将创建一个计算字段,以秒为单位获取两个日期之间的差异。

=DATEDIFF("s", Fields!START_DATE.Value, Fields!END_DATE.Value)

然后,文本框表达式将在计算中使用DIFF字段:

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

以下是一些示例数据和结果:

1