Check if date is between two dates

Hi

Is there a function in vs 2005 (vb.net) to check if a date is between two dates?

Thx

LVL 1
AWestEngAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can simplify it AkisC...

    Public Function isThisDateBetween(ByVal startDate As Date, ByVal endDate As Date, ByVal inBetweenDate As Date) As Boolean
        Return inBetweenDate >= startDate AndAlso inBetweenDate <= endDate
    End Function
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if the variable is datetime, you can simply use the <= and >= operator to compare the date values...
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
AkisCCommented:
Why bother. Make your own.
Dim isD As Boolean = isThisDateBetween("08/08/2007", "10/10/2007", "09/09/2007")

    Public Function isThisDateBetween(ByVal startDate As Date, ByVal endDate As Date, ByVal inBetweenDate As Date) As Boolean
        Dim yesIs As Boolean = False
        If inBetweenDate >= startDate Then
            If inBetweenDate <= endDate Then
                yesIs = True
            End If
        End If
        Return yesIs
    End Function
0
 
AkisCCommented:
Hi Idle_Mind
In the months that I am an EE member, your comments have helped me a lot.
Just a question. I think that the AndAlso statement will not check the 2nd condition if the first is true, -but- I am confused with the difference of And - AndAlso

I have the habbit when explaining something (I was teaching in the past) to make small statment that the other will understand. Indeed your code is better formed!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You've got the idea...but stated it backwards.  ;)

"AndAlso" is known as a "short circuited" boolean operator.  It does NOT check the second expression if the first is FALSE since the resulting "And" operation cannot be True with the one operand already evaluated as False.

Some documentation:
http://msdn2.microsoft.com/en-us/library/wz3k228a(vs.71).aspx
http://support.microsoft.com/kb/817250
0
 
AkisCCommented:
Thank you :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.