# 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
###### Who is Participating?

Middle 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

Billing EngineerCommented:
if the variable is datetime, you can simply use the <= and >= operator to compare the date values...
0

Commented:
0

Commented:
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

Commented:
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

Middle 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

Commented:
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.