I have a DatagridView
with hours hh:mm:ss
how I could add up all those hours. I have the following but it does not work for me, it adds the time as a string. For example, 9:22:347:24:14
Dim horasT
For Each row In Datos.Rows
If row.Cells(6).Value.ToString() <> "0" Then
horasT += CDate(row.Cells(6).Value), "hh:mm:ss")
End If
Next
Good..
You have a couple of problems with the code. You're not defining the data type of hoursT, so the compiler infers it, and from what you're saying it infers it as text (I don't know why).
Also, you're using the old CDate function, instead of using a datetime or timespan object, or whatever you like to handle this.
Those Objects have an add method, which is used to add another object of the same type to them.
Find out which one suits you best according to your case.
I found this that might help you:
Alcides Salazar. Because you only want to add the time, and your column in your
DataGridView
where is the time with format hh:mm:ss, I have solved it with the following code that I show you below:The key part of the code is in saving and adding the time as
TimeSpan
and not inDate
.