|
-
May 2nd, 2002, 10:37 AM
#1
2 dates...?
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!
-
May 2nd, 2002, 10:45 AM
#2
Bouncy Member
VB Code:
If dtmMyDate >= #12/15/2002# And dtmMyDate <= #1/15/2003# Then
MsgBox "yup"
Else
MsgBox "nope"
End If
-
May 2nd, 2002, 10:48 AM
#3
Fanatic Member
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
Martin J Wallace (Slaine)
-
May 2nd, 2002, 10:50 AM
#4
Member
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"
-
May 2nd, 2002, 10:53 AM
#5
Fanatic Member
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
Martin J Wallace (Slaine)
-
May 2nd, 2002, 11:02 AM
#6
Bouncy Member
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"
it depends what country you're from 
more specifically it depends on your computers regional settings.
-
May 3rd, 2002, 05:36 AM
#7
It's true. I'm from Brazil and this functions should work fine here too.
Thanks all!
-
May 3rd, 2002, 05:46 AM
#8
Bouncy Member
cool.
to get around it format as dd/mmm/yyyy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|