I'm having a liitle issue with a basic hire app in calculating the hire period. I would like to show the hire period in days by calculating the hours not the dates.
As an example if somebody collects a car at 8am on Monday but returns it at 8am on tuesday this will be classed as 1 day. My currunt app thinks it's 2 days as it goes past midnight on the timedate picker.
the code below is what I'm using to calculate the days between two timedate pickers:
hire_PeriodTextBox.Text = (dateTimePicker2.Value - dateTimePicker1.Value.AddDays(-1)).Days.ToString()
the date time pickers are in this format: dd/MM/yyyy HH:mm:ss
Calculate days on hours rather than date
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Jul 25, 2012, 2:30 AM EDT
TimeSpan ts = dateTimePicker2.Value - dateTimePicker1.Value;
int days = (int)(ts.TotalHours/24.0);
hire_PeriodTextBox.Text = days.ToString():
Niravkumar Vaghela38 reputationPosted Jul 25, 2012, 4:02 AM EDT
You can try this:
DateTime departure = new DateTime(2010, 6, 12, 18, 32, 0);
DateTime arrival = new DateTime(2010, 6, 13, 22, 47, 0);
TimeSpan travelTime = arrival - departure;
Find more examples at
http://msdn.microsoft.com/en-us/library/system.timespan.aspx
Hope this will help you.
mike DelvottiRank #7,298 · 244 reputationPosted Jul 25, 2012, 4:24 AM EDT