mike Delvotti

mike Delvotti

  • NA
  • 262
  • 0

Calculate days on hours rather than date

Jul 25 2012 6:19 AM
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

Answers (3)