addition of hours and also minutes in gridview i.e subtotal and grand total.

hi folks, i'm in a trouble dat i want to add both hours and minutes taken i.e sub-total and grand total of that addition. i have seen many forums but they have given for only hours to be calculated. but i need both to be calculated simultaneously.
Who is Participating?
Bob LearnedConnect With a Mentor Commented:
Are you saying that you have a string column that has hours and minutes, and you need to calculate a sum?


Duration      Decimal
-----------      -----------
1:30            1.5
1:34            1.566667
1:35            1.583333
1:45            1.75
======      =======
6:24            6.4

Decimal = Hours + (Minutes / 60)
Time = INT(Decimal) & ":" & (Decimal - INT(Decimal) * 60)
Bob LearnedCommented:
You should be able to use either the Date structure, or a TimeSpan to do the necessary calculations to get hours and minutes.


Dim dt1 As New Date(2008, 1, 1, 23, 0, 0)
Dim dt2 As Date = Now
Dim ts As TimeSpan = dt2.Subtract(dt1)
Dim hours As Integer = ts.Hours
Dim minutes As Integer = ts.Minutes

Open in new window

Jeff CertainCommented:
It's a little unclear if the asker wants total minutes taken, in which case the code above needs to be tweaked slightly

Dim totalMinutes As Integer = 60 * ts.Hours + ts.Minutes

Other than that, TheLearnedOne is bang on (as usual)
digmaxAuthor Commented:
no actually i need to add the total time in the gridview. but the problem coming is its in hrs and mins format, so how to make the addition i.e subtotals
All Courses

From novice to tech pro — start learning today.