Crystal Report Function for converting Seconds to Timespan format

帅比萌擦擦* 提交于 2019-12-08 14:07:03

问题


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

回答1:


You could easily alter my ElapsedTime() function to meet your needs.



来源:https://stackoverflow.com/questions/2402210/crystal-report-function-for-converting-seconds-to-timespan-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!