I am trying to calculate hour worked based on a start date and an end date that the user picks. If the dates are on the same day I have no problem getting the hours but I am having trouble with it if they pick multiple days. I need it to return 8 hours if the person was off for the whole day but I am getting back 24 hours if they are off for 2 days, here is how I am attempting to solve this now, any help would be appreciated. I know this is a mess that is why I am asking for some help.
VB.NET:
'--Loop through every date in range provided by user
While curDate <= Me.dtpEndDate.Value.Date
'--Do NOT count Sunday, Saturday or Holidays, they are not work days.
If curDate.DayOfWeek <> DayOfWeek.Saturday And curDate.DayOfWeek <> DayOfWeek.Sunday _
And HolidayChecker(curDate) = False Then
tempNewHrs = 0
startTime = Me.dtpStartDate.Value.TimeOfDay.ToString() 'Set current time
endTime = Me.dtpEndDate.Value.TimeOfDay.ToString() 'Set current time
If Me.dtpEndDate.Value.Date = Me.dtpStartDate.Value.Date Then
'tempNewHrs = 0
tempNewHrs = tempNewHrs + DateDiff(DateInterval.Minute, Me.dtpStartDate.Value, Me.dtpEndDate.Value)
tempTotalHrs = tempTotalHrs + tempNewHrs
ElseIf Me.dtpEndDate.Value.Date <> curDate Or Me.dtpStartDate.Value.Date <> curDate Then
tempNewHrs = tempNewHrs + 8
tempTotalHrs = tempTotalHrs + tempNewHrs
ElseIf Me.dtpStartDate.Value.TimeOfDay.ToString() > tempStartTimeString Then
tempNewHrs = DateDiff(DateInterval.Minute, Me.dtpStartDate.Value, tempEndTimeString)
End If
End If
'--Increment to next day
curDate = curDate.AddDays(1)
End While