I need help on how to calculate the total work hours in a 12 hour format. I have a database that has the columns for the time in and time out as well as the total hours.

Try
            If txtSCANRFID.Text = "" Then

            Else
                reloadtxt("SELECT * FROM students WHERE RFIDNumber= '" & txtSCANRFID.Text & "' ")

                If dt.Rows.Count > 0 Then
                    reloadtxt("SELECT * FROM attendance_students WHERE RFIDNumber='" & txtSCANRFID.Text & "' AND Date='" & lblDATEtime.Text & "' AND Time_Out ")

                    If dt.Rows.Count > 0 Then

                        lblSTATUS.Text = ""
                        lblDONE.Text = "Time In and Time Out 
    already recorded"

                    Else
                        reloadtxt("SELECT * FROM attendance_students WHERE RFIDNumber='" & txtSCANRFID.Text & "' AND Date='" & lblDATEtime.Text & "' ")
                        If dt.Rows.Count > 0 Then

                            updatesLogged("UPDATE attendance_students SET Time_Out='" & TimeOfDay & "', Total_Hours= Time_Out-Time_In WHERE RFIDNumber='" & txtSCANRFID.Text & "' AND Date='" & lblDATEtime.Text & "' ")
                            lblSTATUS.Text = "TIME OUT"

                        Else
                            createLogged("INSERT INTO attendance_students (RFIDNumber,Surname,FirstName,Date,Time_In) VALUES ('" & txtSCANRFID.Text & "', '" & lblLastName.Text & "', '" & lblFirstName.Text & "', '" & lblDATEtime.Text & "', '" & TimeOfDay & "' ) ")
                            lblSTATUS.Text = "TIME IN"

                        End If

                    End If
                Else

                End If

            End If

        Catch ex As Exception

        End Try

The time in and time out works fine but I couldn't get the total work hours between the two time. The result gives me incorrect result such as negative total hour. Can you correct my code? This is for my capstone project. Thank you.

While it is an extra step, I would recommend converting the date text value to a System.DateTime value and perform the operations on that before converting back to text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.