none
Sum time in time format RRS feed

  • Question

  • I am looking for a solution to sum time in total line in time format in SSRS 2008. 

    Thanks in advance.

    Tuesday, January 25, 2011 3:26 PM

Answers

  • The following function will take a number of seconds and calculate the number of days, hours, minutes & seconds... In the following format: dd:hh:mm:ss

    Function DHMS(NumberOfSeconds as Long) as String
     Dim NumberOfMinutes as Long
     Dim NumberOfHours as Long
     Dim NumberOfDays as Long
    NumberOfDays = NumberOfSeconds \ 86400 NumberOfSeconds = NumberOfSeconds Mod 86400 NumberOfHours = NumberOfSeconds \ 3600 NumberOfSeconds = NumberOfSeconds Mod 3600 NumberOfMinutes = NumberOfSeconds \ 60 NumberOfSeconds = NumberOfSeconds Mod 60 DHMS = IIf(NumberOfDays < 10, "0" & NumberOfDays, NumberOfDays) & " : " & _ IIf(NumberOfHours < 10, "0" & NumberOfHours, NumberOfHours) & " : " & _ IIf(NumberOfMinutes < 10, "0" & NumberOfMinutes, NumberOfMinutes) & " : " & _ IIf(NumberOfSeconds < 10, "0" & NumberOfSeconds, NumberOfSeconds) End Function

     

    Then you reference the the code in a formula like this...

     

    =Code.DHMS(Fields!DiffSecs.Value)

    Jason Long
    • Marked as answer by sappunni Tuesday, January 25, 2011 6:27 PM
    Tuesday, January 25, 2011 6:20 PM

All replies

  • hello, can you give more details in what you are trying to do?  thanks
    Tuesday, January 25, 2011 4:40 PM
  • I have a column which is the time the user has spent on differnt tasks like loging in, contact customer, etc the format of the time is in time(7) format hh:mm:ss:xxxxxxx when I try to do =sum(Fields!Timespent.Value) I get a 00:00:00:000000

    The values in the column timespent are like 02:22:00:000000 00:59:00:000000 etc

    Thank you!!!

    Tuesday, January 25, 2011 4:58 PM
  • The following function will take a number of seconds and calculate the number of days, hours, minutes & seconds... In the following format: dd:hh:mm:ss

    Function DHMS(NumberOfSeconds as Long) as String
     Dim NumberOfMinutes as Long
     Dim NumberOfHours as Long
     Dim NumberOfDays as Long
    NumberOfDays = NumberOfSeconds \ 86400 NumberOfSeconds = NumberOfSeconds Mod 86400 NumberOfHours = NumberOfSeconds \ 3600 NumberOfSeconds = NumberOfSeconds Mod 3600 NumberOfMinutes = NumberOfSeconds \ 60 NumberOfSeconds = NumberOfSeconds Mod 60 DHMS = IIf(NumberOfDays < 10, "0" & NumberOfDays, NumberOfDays) & " : " & _ IIf(NumberOfHours < 10, "0" & NumberOfHours, NumberOfHours) & " : " & _ IIf(NumberOfMinutes < 10, "0" & NumberOfMinutes, NumberOfMinutes) & " : " & _ IIf(NumberOfSeconds < 10, "0" & NumberOfSeconds, NumberOfSeconds) End Function

     

    Then you reference the the code in a formula like this...

     

    =Code.DHMS(Fields!DiffSecs.Value)

    Jason Long
    • Marked as answer by sappunni Tuesday, January 25, 2011 6:27 PM
    Tuesday, January 25, 2011 6:20 PM
  • Jason.

    I was able to sum the time by

    =TimeSpan.FromTicks(Sum(Fields!TotalTime.Value))

    Thursday, February 3, 2011 10:02 PM
  • Hi I have tried the above and receive the following error when in preview "There is an error on Line 15 of custom code: [BC30203] Identifer expected
    Friday, June 22, 2012 8:14 AM