Summing Timespans

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a datagrid with a start and an end time. I subtract the start time
from the end time in each row and place the difference into a TimeSpan
variable. Now I want to total up the Timespans and get the total number of
hours taken.

Dim HourSum as Decimal = 0.0

Later in a method I call

HoursSum += Convert.ToDecimal(Hours) **error - doesn't like type cast.

So how do I total up a TimeSpan?
 
Bill,

Where did you get these statements.

I will try to make it clear with some simple statements.

\\\
Dim span As TimeSpan = Now.Subtract(Now.AddHours(-2))
Dim hours As Decimal = span.Hours
///

I hope this helps,

Cor
 
BillG said:
I have a datagrid with a start and an end time. I subtract the start time
from the end time in each row and place the difference into a TimeSpan
variable. Now I want to total up the Timespans and get the total number of
hours taken.

Dim HourSum as Decimal = 0.0

Later in a method I call

HoursSum += Convert.ToDecimal(Hours) **error - doesn't like type cast.

So how do I total up a TimeSpan?

Any reason you particularly want to convert them to decimal? You can
just add TimeSpans together as they are without converting them to a
different type first.
 
Back
Top