How to Format Seconds as Time in SSRS

2014-11-13

This comes up now and again and I always seem to forget how I did it last time, so I am posting this here for safekeeping.

In the code page (Report > Report Properties > Code) add the function:

    Function formatSeconds(ByVal secs As Integer) As String

        Dim t As TimeSpan = TimeSpan.FromSeconds(secs)
        Return String.Format("{0:D2}:{1:D2}:{2:D2}",
                    t.Hours,
                    t.Minutes,
                    t.Seconds)

    End Function

For the Cell that you want to format, call the function:

And the date will be formatted as so - it's nice way to express duration in a more readable way, especially when rows may have tens of thousands of seconds:













Mark Wojceichowicz

Labels: