Crystal Report Function for converting Seconds to Timespan format.

Posted by arakkots on Stack Overflow See other posts from Stack Overflow or by arakkots
Published on 2010-03-08T15:04:46Z Indexed on 2010/03/08 15:06 UTC
Read the original article Hit count: 269

I have a crystal report where it shows the Agent's activities throughout the day with a pie chart. In the details section it is displaying:

  • Activity [string]
  • StartedAt [DateTime]
  • EndedAt [DateTime]
  • Duration [The difference between EndedAt and StartedAt in seconds - Integer]

Report data is GroupedBy Activity and summarized by Duration.

Currently Duration is shown in seconds but I need to format it 02h:30m:22s:15ms. For that I wrote a custom function in Crystal Report in the Formula Workshop editor as follows, but it looks like the syntax is not right (Error message on keyword Long: "A variable type (for example, 'String') is missing."). Can someone help?

Function GetTimeSpanString(seconds as Long)
    Dim ts As TimeSpan = TimeSpan.FromSeconds( seconds );
    GetTimeSpan = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",  
                            ts.Hours,  
                            ts.Minutes,  
                            ts.Seconds,  
                            ts.Milliseconds) 
End Function

© Stack Overflow or respective owner

Related posts about crystal-reports

Related posts about custom