Date Between Problem
I need to determine if a date is between 2 other dates. Simple enough. But what if the ending date is in a different year.
Specifically, whether <date> is between Nov 30 and Feb 21. And it needs to be flexible enough to work if <date> is after Jan 1.
I've tried lots of options but there is a problem with each.
Surely this is a common enough problem that somebody else has solved it by now.
[440 byte] By [
R3dD0g] at [2007-11-11 7:26:07]

# 1 Re: Date Between Problem
Dim StartDate As Date
Dim EndDate As Date
Dim TestDate As Date
StartDate = #11/30/2005#
EndDate = #2/21/2006#
TestDate = Date
If StartDate <= TestDate Then
If TestDate <= EndDate Then
MsgBox TestDate & " is between " & StartDate & " and " & EndDate
End If
End If
# 2 Re: Date Between Problem
Thanks for the quick reply.
I was trying to do it in a single if clause. And it caused lots of problems.
Thanks.
R3dD0g at 2007-11-11 17:27:56 >

# 3 Re: Date Between Problem
You could do this:
If StartDate <= TestDate And TestDate <= EndDate Then
but then VB will perform both tests, even if one of them is False. Nested (a.k.a. short-circuited) Ifs are marginally more efficient.