问题
I need to generate the time difference between tow dates in SSRS in HH:MM format. How can i achieve this? My data source is MS CRM FetchXML.
Eg : Date1 : 01/01/2016 04:05 AM Date2 : 01/03/2016 02:15 PM Time Differece Should be : 58:10
Regards, Sandeep
回答1:
I might be a little too late but was needing to calculate the elapsed time between two times. Hence I stumbled up this link
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/26d8b4fc-6862-42a0-ac7f-0caa93ba2fde/to-find-ellapse-time-in-ssrs-2008?forum=sqlreportingservices
The below expression worked for me. I also found it is simpler to do it in SSRS than SQL.
=Datediff("h",Fields!StartDate.value,Fields!EndDate.value) & ":" & Datediff("n",Fields!StartDate.value,Fields!EndDate.value) mod 60 & ":" & Datediff("s",Fields!StartDate.value,Fields!EndDate.value) mod 60
The result of the above will be HH:MM:SS
回答2:
Try this:
=DateDiff(
DateInterval.Hour,CDATE("01/01/2016 04:05 AM"), CDATE("03/01/2016 02:15 PM")
) & ":" &
DateDiff(
DateInterval.Minute,CDATE("01/01/2016 04:05 AM"), CDATE("03/01/2016 02:15 PM")
) Mod 60
It will produce 58:10
Replace CDATE() by the field or parameter containing your date time value.
Let me know if this helps.
回答3:
Write a custom code to calculate time difference between two dates and return a string as expecting HH:MM like
Public Function GetTimeDifference(ByVal dt1 AS DATETIME,ByVal dt2 AS DATETIME) AS String
Dim Mn AS Integer=DateDiff("n",dt1,dt2)
Dim HH AS Integer=Mn /60
Dim MM AS Integer=Mn Mod 60
Return HH.ToString() & ":" & MM.ToString()
End Function
Now call this function as an expression like
=Code.GetTimeDifference(Parameters!startDate.Value,Parameters!endDate.Value)
来源:https://stackoverflow.com/questions/36029317/calculate-the-time-difference-between-two-dates-in-hhmm-format-using-ssrs