Comparing 3 dates

S

Steve

Hi
I need a function that will determine whether a date falls between two other
dates. If the date does fall within the time band, the function will return a
"yes", if it doesn't it will return a "no"

Thanks

Steve
 
J

Jon Ley

Untested air code ...

Public Function CheckDateRange (vntCheckDate As Date, vntStart As Date,
vntEnd As Date) As Boolean

CheckDateRange = (vntCheckDate > vntStart) And (vntCheckDate < vntEnd)

End Function

If you want "Yes"/"No" instead of boolean True/False then you will need to
change your return type to String instead of Boolean and use an If statement:

If (vntCheckDate > vntStart) And (vntCheckDate < vntEnd) Then
CheckDateRange = "Yes"
Else
CheckDateRange = "No"
End If

You might also want to change < to <= and/or > to >= depending on whether or
not the start and end dates of your range should return Yes or No. If they're
both inclusive (<= and >=) then you could use Between:

If vntCheckDate Between vntStart And vntEnd Then

HTH,

Jon.
 
Top