Comparing 3 dates

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top