Hi guys!
I have a code here that compute the night differential of the employees. Its working 100%. I just wanted to ask if there is a shorter method to do this. There are a lot of conditions that should be met like if the employee's are late, employees went under-time, employees are absent or that specific date is rest day, and if schedule is within the night differential time.
Below is my code for the night differential.
Again, the code is 100% working for me and I just wanted to know if there are other ways to do this. Night Differential starts at 10:00 PM and ends at 6:00 AM. The time format is "MM/dd/yyyy hh:mm" because sometimes, the time-out of the employees goes through the next day.
If you do know and if you have some extra time to do it or there are a few mistakes that I've made, kindly please let me know. Thanks! :wave:
I have a code here that compute the night differential of the employees. Its working 100%. I just wanted to ask if there is a shorter method to do this. There are a lot of conditions that should be met like if the employee's are late, employees went under-time, employees are absent or that specific date is rest day, and if schedule is within the night differential time.
Below is my code for the night differential.
Code:
'Compute Night Differential
If restday = True Then
lvResult.SubItems.Add("0")
Else
If status1 = "No Login" Or status2 = "No Logout" Then
lvResult.SubItems.Add("0")
Else
Dim ndiffStart As Date = schedIn.Date & " 10:00 PM"
Dim ndiffEnd As Date = schedOut.Date & " 6:00 AM"
Dim nightdiff1 As Integer
Dim nightdiff2 As Integer
Dim totaldiff As Integer
nightdiff1 = DateDiff(DateInterval.Hour, ndiffStart, schedIn)
nightdiff2 = DateDiff(DateInterval.Hour, ndiffEnd, schedOut)
If nightdiff1 >= 0 Then
If timeOut >= schedOut Then
totaldiff = DateDiff(DateInterval.Hour, ndiffStart, ndiffEnd)
Else
totaldiff = DateDiff(DateInterval.Hour, schedIn, ndiffEnd)
End If
lvResult.SubItems.Add(totaldiff)
Else
nightdiff2 = DateDiff(DateInterval.Hour, schedOut, ndiffStart)
If nightdiff2 > 0 Then
If schedIn > timeIn Then
totaldiff = DateDiff(DateInterval.Hour, schedIn, ndiffEnd)
Else
totaldiff = DateDiff(DateInterval.Hour, timeIn, ndiffEnd)
End If
If nightdiff2 > 0 Then
lvResult.SubItems.Add(totaldiff)
Else
lvResult.SubItems.Add("0")
End If
Else
totaldiff = DateDiff(DateInterval.Minute, ndiffStart, timeIn)
If totaldiff > 0 Then
totaldiff = DateDiff(DateInterval.Hour, timeIn, schedOut)
Else
totaldiff = DateDiff(DateInterval.Hour, ndiffStart, schedOut)
End If
lvResult.SubItems.Add(totaldiff)
End If
End If
End If
End If
If you do know and if you have some extra time to do it or there are a few mistakes that I've made, kindly please let me know. Thanks! :wave: