• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4936
  • Last Modified:

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

0
AWestEng
Asked:
AWestEng
4 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if the variable is datetime, you can simply use the <= and >= operator to compare the date values...
0
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now