Excel

Wednesday, December 7, 2011

SSRS Custom Code to Convert minutes into HH:MM format



To Convert the Integer values into “HH:MM” format in SSRS:

Write the following VB.Net code in Custom Code area (Right click on report -> Report Properties -> Code)

Function ToHHMM(Minutes As Integer) As String
Dim RetValue As String
Dim min As Integer
RetValue = "0000:00"
If Minutes < 0 Then Minutes = Minutes * -1
RetValue = Fix(Minutes / 60)
min = Minutes Mod 60
If min < 10 Then
RetValue = RetValue + ":0" + CStr(min)
Else
RetValue = RetValue + ":" + CStr(min)
End If
ToHHMM = RetValue
End Function

Now, use the following value expression “ =Code.ToHHMM(Fields!TotalMinutes.Value) in the report area.

(Considered that the field “TotalMinutes” contains the minute value to be converted into HH:MM format.)

Result : You will get the minute value “185” as “03:05”

2 comments:

  1. Thank you That was very helpful

    ReplyDelete
  2. Hi, Thanks this works well. What would be the expression to sum the column and format in HH:MM) Many thanks for a puzzled Accountant, who is trying to get to grips with SSRS...

    ReplyDelete