0
votes

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())
1

1 Answers

0
votes

I would do it by accessing the properties of the datepicker.

So for hours, you can use:

Dim hour1 As Integer = 0
Dim hour2 As Integer = 0
Dim hourTotal As Integer = 0
hour1 = datepicker1.value.hour
hour2 = datepicker2.value.hour
hourTotal = hour2 - hour1

Same goes for the minute. Just replace .hour to .minute