Results 1 to 5 of 5

Thread: [resolved]Issue with determining time

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Location
    Seminole, FL
    Posts
    30

    [resolved]Issue with determining time

    In my app I've written I'm trying to determine what shift it is. The issue I'm having is that after midnight my code doesn't determine what shift it is. I think it's because my constants are assigning date and time when I hover over them even though I'm only assigning time. I'm still pretty new to .Net so I'm kind of learning on the fly. Here is my code.

    Code:
        Dim DateAndTime As String
        Dim Time1 As DateTime = DateTime.Parse("06:00:00")
        Dim Time2 As DateTime = DateTime.Parse("14:00:00")
        Dim Time3 As DateTime = DateTime.Parse("22:00:00")
        Dim CurrentShift As String
        Dim i As Short
    
            DateAndTime = Now
    
            If Is1stShift(Time1, Time2) = True Then
                CurrentShift = "1"
            End If
    
            If Is2ndShift(Time2, Time3) = True Then
                CurrentShift = "2"
            End If
    
            If Is3rdShift(Time3, Time1) = True Then
                CurrentShift = "3"
            End If
    
        Public Function Is1stShift(ByVal Time1 As DateTime, ByVal Time2 As DateTime) As Boolean
            Return DateTime.Now.TimeOfDay >= Time1.TimeOfDay AndAlso DateTime.Now.TimeOfDay <= Time2.TimeOfDay
        End Function
    
        Public Function Is2ndShift(ByVal Time2 As DateTime, ByVal Time3 As DateTime) As Boolean
            Return DateTime.Now.TimeOfDay >= Time2.TimeOfDay AndAlso DateTime.Now.TimeOfDay <= Time3.TimeOfDay
        End Function
    
        Public Function Is3rdShift(ByVal Time3 As DateTime, ByVal Time1 As DateTime) As Boolean
            Return DateTime.Now.TimeOfDay >= Time3.TimeOfDay AndAlso DateTime.Now.TimeOfDay <= Time1.TimeOfDay
        End Function
    Last edited by N20D5OH; Dec 17th, 2008 at 07:11 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width