Issues calculating total hours using timespan

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tnynyn
    New Member
    • Dec 2010
    • 1

    #1

    Issues calculating total hours using timespan

    I have created a form with two datetimepicker showing only hours (start and end times). I have timespan calculating the total hours, but when it goes to the next day, it adds 24 hours. For example, from 9PM to 11PM it calculates 2 hours total, but when it goes from 9Pm to 12AM, it jumps to 21 hours. I want it show 3 hours instead, but not sure how to do this. Heres what I have so far:

    Code:
    timeEnd.Format = DateTimePickerFormat.Custom;
    timeEnd.CustomFormat = "hh:mm tt";
    TimeSpan ts = timeEnd.Value - timeStart.Value;
    lblTime.Text = "Total Time: " + (ts.Duration());
Working...