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
Loading
VulpesPosted Jul 25, 2012, 6:30 AM
TimeSpan ts = dateTimePicker2.Value - dateTimePicker1.Value;
int days = (int)(ts.TotalHours/24.0);
hire_PeriodTextBox.Text = days.ToString():
mike DelvottiPosted Jul 25, 2012, 8:24 AM
Niravkumar VaghelaPosted Jul 25, 2012, 8:02 AM
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.