How to check whether the current time is between 3am and 3:30am
You can use an condition like this:
Dim StartTime As DateTime = #7/29/1954 2:25:25 AM# 'this should be before EndTime Dim EndTime As DateTime = #2/5/1975 6:00:15 PM# 'this should be after StartTime Dim TSendTM As TimeSpan = EndTime.TimeOfDay 'get only the time portion Dim TSstrtTM As TimeSpan = StartTime.TimeOfDay 'for start and end Dim CurrentTime As TimeSpan = DateTime.Now.TimeOfDay If CurrentTime.TotalMilliseconds >= TSstrtTM.TotalMilliseconds AndAlso _ CurrentTime.TotalMilliseconds <= TSendTM.TotalMilliseconds Then Debug.WriteLine("Time is within range.") End If
Datetime.Parse( StopTime1)< Datetime.Parse(Now.ToString(“hh:mm:ss”)) And Datetime.Parse(Now.ToString(“hh:mm:ss”))< Datetime.Parse(StopTime2)
StopTime1 and StopTime2 are String variables
This one worked
as long as you creat those stoptime variables using the same day, you will be ok