MadsTheMan MadsTheMan - 9 months ago 22 Question How can I execute a task between certain hours only

I have a private sub

that does stuff and I have a timer
that is going to execute
. Right now its executing each minute, 24/7 - but I want it to only execute between certain hours only. Which would be between 07:00 - 23:59:59. How can I set that "propertie"?

Below is what my TimerAverage.tick does at the moment and also what I'm trying to accomplish.

Private Sub TimerAverage_Tick(sender As Object, e As EventArgs) Handles TimerAverage.Tick

Dim dateValue As DateTime = DateTime.Now
Dim startTime As DateTime = dateValue.Date + New TimeSpan(07, 0, 0)
Dim endTime As DateTime = dateValue.Date + New TimeSpan(23, 59, 0)

''''' Below is a demonstration of what I want (which obviously don't work)

''''' If not is between starttime
' Do nothing



'end if

I know this is a bad attempt, its more like a demonstration of what I'm trying to accomplish. I've tried to figure out how to write this correctly, but I can't figure it out.


If the range is 7:00 - 23:59 you could simply use:

If DateTime.Now.Hour >= 7 Then
    'do something
End If