How to check if a date is between other 2 dates?
For example:
I'd like to see if the date 01/01/2003 is between 15/12/2002 and 15/01/2003.
Thanks!
Printable View
How to check if a date is between other 2 dates?
For example:
I'd like to see if the date 01/01/2003 is between 15/12/2002 and 15/01/2003.
Thanks!
VB Code:
If dtmMyDate >= #12/15/2002# And dtmMyDate <= #1/15/2003# Then MsgBox "yup" Else MsgBox "nope" End If
try
VB Code:
If (cdate("01/01/2003") > cdate("15/12/2002")) and (cdate("01/01/2003") < cdate("15/01/2003")) then 'True Else 'False end if
i dont believe that test will work because it seems as if the dates are in the wrong order.
wouldn't it have to be
"12-15-02" not "15-12-02"
Or even better, a little function for you.
VB Code:
Private Function bBetweenDates(strDateToCheck As String, strLowerDate As String, strUpperDate As String, Optional bThru As Boolean = False) As Boolean Select Case bThru Case True 'Thru If (CDate(strDateToCheck) >= CDate(strLowerDate)) And (CDate(strDateToCheck) <= CDate(strUpperDate)) Then bBetweenDates = True Else bBetweenDates = False End If Case False 'Between If (CDate(strDateToCheck) > CDate(strLowerDate)) And (CDate(strDateToCheck) < CDate(strUpperDate)) Then bBetweenDates = True Else bBetweenDates = False End If End Function
it depends what country you're from :)Quote:
Originally posted by ibowlwell
i dont believe that test will work because it seems as if the dates are in the wrong order.
wouldn't it have to be
"12-15-02" not "15-12-02"
more specifically it depends on your computers regional settings.
It's true. I'm from Brazil and this functions should work fine here too.
Thanks all!
cool.
to get around it format as dd/mmm/yyyy ;)