date time logic issue

karthikeyan

Member
Joined
Oct 22, 2005
Messages
12
Programming Experience
Beginner
hi,
i have three slots ie
total working hours=24
works starts from
slot1: 8am to 5pm
slot2: 5pm to 12am
slot3: 12am to 8am

say for example if i am working morning 6am to 3 pm(in the same day) i wan to check in which time slots i worked.(in this example i worked 2 hours in slot3 and 7 hours in slot1). so like this i want to find the slots if we give the time can anyone help me to do with example coding please
 
hi
i used this following logic:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


Dim strwrk As DateTime = "3:00 AM"
Dim endwrk As DateTime = "3:00 PM"
Dim hrs() As Double = SlotHours(strwrk, endwrk)

End Sub

Private Function SlotHours(ByVal strwrk As DateTime, ByVal endwrk As DateTime) As Double()
Dim slot1 As DateTime = #8:00:00 AM#
Dim slot2 As DateTime = #5:00:00 PM#
Dim slot3 As DateTime = #12:00:00 AM#
Dim slothrs(2) As Double

Dim hrswrk As Double
If strwrk > endwrk Then
hrswrk = endwrk.AddDays(1).Subtract(strwrk).TotalHours
Else
hrswrk = endwrk.Subtract(strwrk).TotalHours
End If
If hrswrk < 0 Then
hrswrk = hrswrk * -1
End If

Select Case strwrk
Case Is >= slot2
slothrs(1) = slot3.AddDays(1).Subtract(strwrk).TotalHours
slothrs(2) = hrswrk - slothrs(1)
If slothrs(2) > 8 Then
slothrs(0) = slothrs(2) - 8
slothrs(2) = 8
End If
Case Is >= slot1
slothrs(0) = slot2.Subtract(strwrk).TotalHours
slothrs(1) = hrswrk - slothrs(0)
If slothrs(1) > 7 Then
slothrs(2) = slothrs(1) - 7
slothrs(1) = 7
End If
Case Is >= slot3
slothrs(2) = slot1.Subtract(strwrk).TotalHours
slothrs(0) = hrswrk - slothrs(2)
If slothrs(0) > 9 Then
slothrs(1) = slothrs(0) - 9
slothrs(0) = 9
End If
End Select


Return slothrs
End Function

in this logic every thing is working but if i give 8:00am to 8:00 am it gives invalid time,rest ofthen works,now any one can help please
 
Back
Top