By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,209 Members | 1,834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,209 IT Pros & Developers. It's quick & easy.

Issues calculating total hours using timespan

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. timeEnd.Format = DateTimePickerFormat.Custom;
  2. timeEnd.CustomFormat = "hh:mm tt";
  3. TimeSpan ts = timeEnd.Value - timeStart.Value;
  4. lblTime.Text = "Total Time: " + (ts.Duration());
  5.  
Dec 5 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.