I've been asked to make a change to a form but a bit unsure how to tackle it:
The number of hire days calculation needs changing.
If the start date and end date are the same the calculation should be one day- it is done on a 24 hour basis – calculate the number of hours, divide by 24 and round up to the nearest whole number
So from 14/11/2013 08.00 to 14.11.2013 20.30 is 12.5 hours - 12.5 divided by 24 = 0.52 round up = 1 day
14.11.2013. 08.00 to 15.11.2013 20.30 is 36.5 hours – 36.5/24= 1.52 – round up = 2 days
can anyone help??
this is my code at the moment:
private void noOfDaysRequired()
{
decimal days = 0;
if (txtEndTimeHH.Text != "" || txtEndTimeMM.Text != "")
{
DateTime bookingStartTime = DateTime.Parse(txtStartDate.Text + " " + txtStartTimeHH.Text + ":" + txtStartTimeMM.Text);
DateTime bookingEndTime = DateTime.Parse(txtEndDate.Text + " " + txtEndTimeHH.Text + ":" + txtEndTimeMM.Text);
bookingStartTime = bookingStartTime.AddMinutes(15);
TimeSpan noOfDays = bookingEndTime - bookingStartTime;
days = noOfDays.Days;
if (days == 0)
{
days += 1;
}
if (bookingEndTime.TimeOfDay.Ticks > bookingStartTime.TimeOfDay.Ticks)
{
days = days + 1;
}
lblDaysRequired.Text = days.ToString();
}
}