Find time is between the two values

RIAS
RIAS used Ask the Experts™
on
Hello,
In a datetime field how do I determine if the time is between
00:00  to 2:45

example:
Datetime Field :  23/09/2019 00:15
The value is between 00:00  to 2:45
 and should return true

example2:
Datetime Field :  23/09/2019 01:15
The value is between 00:00  to 2:45
 and should return true


example3:
Datetime Field :  23/09/2019 02:46
The value is not between 00:00  to 2:45
 and should return false
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Module Module1

    Sub Main()
        Dim Field As Date

        Field = Date.Parse("23/09/2019 00:15")
        test(Field)
        Field = Date.Parse("23/09/2019 01:15")
        test(Field)
        Field = Date.Parse("23/09/2019 02:46")
        test(Field)
        Console.ReadKey()

    End Sub
    Function test(ByVal Field2 As Date)
        Dim minimum As Date
        Dim maxtime As Date

        minimum = Date.Parse("23/09/2019")
        maxtime = minimum.AddMinutes(2 * 60 + 45)
                    )
        If ((Field2 >= minimum) And (Field2 <= maxtime)) Then
            Console.WriteLine("True")
        Else
            Console.WriteLine("False")
        End If
#Disable Warning BC42105 ' Function doesn't return a value on all code paths
    End Function
#Enable Warning BC42105 ' Function doesn't return a value on all code paths
End Module

Open in new window

Author

Commented:
Thanks David Johnson,
Will try and brb

Author

Commented:
Hello,
Is it a simple way ?
Dim curr As Date = Date.Now
Dim startTime As New Date(curr.Year, curr.Month, curr.Day, 6, 0, 0)
Dim endTime As New Date(curr.Year, curr.Month, curr.Day, 11, 0, 0)
If (curr >= startTime) And (curr <= endTime) Then
    ' Do something
End If
Top Expert 2016

Commented:
that works for current day but you are changing the question around

Author

Commented:
Thanks!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial