I have to sum the hours and minutes using expression in the rdlc report of microsoft report viewer, how can I do the sum of the values shown below?
=Split(CStr(Fields!Ore.Value), " ").GetValue(0) --> 03:30
=Split(CStr(Fields!Ore.Value), " ").GetValue(1) --> 02:00
=Split(CStr(Fields!Ore.Value), " ").GetValue(2) --> 08:00
=Split(CStr(Fields!Ore.Value), " ").GetValue(3) --> 04:30

Amira BedhiafiRank #601 · 4K reputationPosted Mar 5, 2025, 6:54 AM EST
You can use the
Splitfunction to extract the hours and minutes, then convert them to total minutes.For example, for the first value, and repeat this for each time value :
= CInt(Split(CStr(Fields!Ore.Value), ":").GetValue(0)) * 60 + CInt(Split(CStr(Fields!Ore.Value), ":").GetValue(1))You can sum the total minutes using a custom code function in RDLC. Go to Report Properties > Code and add the following code to sum the minutes:
Dim totalMinutes As Integer = 0 Public Function AddMinutes(minutes As Integer) As Integer totalMinutes += minutes Return minutes End Function Public Function GetTotalTime() As String Dim hours As Integer = totalMinutes \ 60 Dim minutes As Integer = totalMinutes Mod 60 Return hours.ToString("00") & ":" & minutes.ToString("00") End FunctionIn your report, use the
AddMinutesfunction to add each time value:=Code.AddMinutes(CInt(Split(CStr(Fields!Ore.Value), ":").GetValue(0)) * 60 + CInt(Split(CStr(Fields!Ore.Value), ":").GetValue(1)))Finally, use the
GetTotalTimefunction to display the total time in "HH:mm " format.