Results 1 to 8 of 8

Thread: 2 dates...?

  1. #1
    AlvaroF1
    Guest

    Question 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!

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    VB Code:
    1. If dtmMyDate >= #12/15/2002# And dtmMyDate <= #1/15/2003# Then
    2.     MsgBox "yup"
    3. Else
    4.     MsgBox "nope"
    5. End If
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641
    try

    VB Code:
    1. If (cdate("01/01/2003") > cdate("15/12/2002")) and (cdate("01/01/2003") < cdate("15/01/2003")) then
    2.     'True
    3. Else
    4.     'False
    5. end if
    Martin J Wallace (Slaine)

  4. #4
    Member ibowlwell's Avatar
    Join Date
    Mar 2002
    Location
    RI
    Posts
    56
    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"

  5. #5
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641
    Or even better, a little function for you.
    VB Code:
    1. Private Function bBetweenDates(strDateToCheck As String, strLowerDate As String, strUpperDate As String, Optional bThru As Boolean = False) As Boolean
    2.    
    3.     Select Case bThru
    4.         Case True 'Thru
    5.             If (CDate(strDateToCheck) >= CDate(strLowerDate)) And (CDate(strDateToCheck) <= CDate(strUpperDate)) Then
    6.                 bBetweenDates = True
    7.             Else
    8.                 bBetweenDates = False
    9.             End If
    10.         Case False 'Between
    11.             If (CDate(strDateToCheck) > CDate(strLowerDate)) And (CDate(strDateToCheck) < CDate(strUpperDate)) Then
    12.                 bBetweenDates = True
    13.             Else
    14.                 bBetweenDates = False
    15.             End If
    16.    
    17. End Function
    Martin J Wallace (Slaine)

  6. #6
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    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.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  7. #7
    AlvaroF1
    Guest

    Thumbs up

    It's true. I'm from Brazil and this functions should work fine here too.

    Thanks all!

  8. #8
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    cool.

    to get around it format as dd/mmm/yyyy
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width