I am creating a VB Class - Employees work time for a single shift which occurs during one working day. does not cross midnight, with breaks of total duration but no specified time . It has 3 date/time pickers Start Time, Finish Time, Break duration time. I want to deduct start time from finish time and deduct break duration to give total time worked. Formatted HH:MM I am going wrong somewhere but cannot put my finger on it, could you please help.
Dim TimeIn As Date = StartTime.Value
Dim TimeOut As Date = FinishTime.Value
Dim Break As Date = BreakPicker.Value
Dim TimeNow As Date = DateTime.Now
Dim TempTime As Date = TimeNow + Break
Dim BreakDuration As System.TimeSpan = TempTime - TimeNow
Dim diff As System.TimeSpan = TimeOut.Subtract(TimeIn)
Dim diff1 As System.TimeSpan = TimeOut - TimeIn
Dim diff2 As Integer = ((TimeOut - BreakDuration) - TimeIn).TotalMinutes
Dim diff3 As System.TimeSpan = TimeNow.Subtract(TimeOut)
If TimeOut <= TimeIn Then
MsgBox("Invalid time")
Exit Sub
End If
Dim TotMins As Integer = diff2
Dim Hours As Integer = Math.Floor(TotMins / 60)
Dim Minutes As Integer = TotMins Mod 60
HoursRequiredBox.Text = (Hours & "h : " & Minutes & "m".ToString())