CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2005
    Posts
    3

    Question Date Range Verification - VB question

    I have a vbp code. i need to verify if a date falls within a specific range:

    example:

    BDate EDate DescBDate DescEDate Falls within range

    10/1/2008 7/31/2009 7/1/2000 3/31/2009 YES

    10/1/2008 7/31/2009 4/1/2009 6/30/2010 YES

    8/1/2009 10/1/2009 8/1/1994 1/31/2009 NO

    7/1/2008 9/30/2008 4/1/2009 6/30/2010 NO

    Can someone tell me how to write the logic for the above date range?

    Thanks,

    Jupi

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Date Range Verification - VB question

    You've got 4 fields and 4 dates where is the range?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Dec 2005
    Posts
    3

    Re: Date Range Verification - VB question

    I want to verify if DescBdate and DescEDate falls within BDate and EDate.

    thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Date Range Verification - VB question

    Here's a little pseudo-code:

    Set a Flag to False.
    Check first set of dates, and mark Flag.
    Check next set of dates, and mark Flag.
    Check value of Flag

    or use SQL, like this: (although it's VB6 code)

    Code:
    Option Explicit
    
    
    
    Private Sub Form_Load()
    Dim dteDate     As Date
    Dim adoRec      As ADODB.Recordset
        dteDate = CDate("7 March 2005 10:04:00AM")
        Set adoRec = GetRecordset(dteDate)
        With adoRec
            Do While Not .EOF
                'your code goes here
                 MsgBox .Fields(0)
                .MoveNext
            Loop
            .Close
        End With
        Set adoRec = Nothing
    End Sub
    
    Private Function GetRecordset(ByVal pdteSearchDate As Date) As ADODB.Recordset
    Dim strSQL      As String
    Dim adoRec      As ADODB.Recordset
        strSQL = "SELECT * "
        strSQL = strSQL & "FROM AS_Createsched "
        strSQL = strSQL & "WHERE AS_Createsched.CSIN_dates = #" & Format$(pdteSearchDate, "d mmm yyyy") & "# "
        strSQL = strSQL & "AND HOUR(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "hh") & " "
        strSQL = strSQL & "AND MINUTE(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "nn") & " "
        Set adoRec = New ADODB.Recordset
        adoRec.Open strSQL, GetConnString, adOpenForwardOnly, adLockReadOnly
        Set GetRecordset = adoRec
        Set adoRec = Nothing
    End Function
    
    Private Function GetConnString() As String
        GetConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db4.mdb;Persist Security Info=False"
    End Function
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Date Range Verification - VB question

    I think you need the BETWEEN statement

  6. #6
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: Date Range Verification - VB question

    Quote Originally Posted by jojupi01 View Post
    I have a vbp code. i need to verify if a date falls within a specific range:

    example:

    BDate EDate DescBDate DescEDate Falls within range

    10/1/2008 7/31/2009 7/1/2000 3/31/2009 YES

    10/1/2008 7/31/2009 4/1/2009 6/30/2010 YES

    8/1/2009 10/1/2009 8/1/1994 1/31/2009 NO

    7/1/2008 9/30/2008 4/1/2009 6/30/2010 NO

    Can someone tell me how to write the logic for the above date range?

    Thanks,

    Jupi
    How the input is given?
    from Database? User interface??
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Date Range Verification - VB question

    To make comparison between dates you'd need the Date data type.
    I assume your dates like 10/1/2008 come as strings, so you have to convert them to Date before being able to compare them.
    Code:
      Dim BD as Date, ED as Date, MD as Date
      BD = CDate("10/1/2008")
      ED = CDate("7/31/2009")
      MD = CDate("7/1/2000")
    
      If BD <= MD And MD <= ED Then Print "in range" Else Print "out"
    CDate can surely be used with string variables, too.
    Assumed BDate and EDate were string variables then BD = CDate(BDate) would do the conversion for BDate.

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Date Range Verification - VB question

    String variables can be used in a sql statement just fine as they are as stated earlier a SQL between statement sounds like the key. Of course the OP has not been back for a while so ...
    Always use [code][/code] tags when posting code.

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

Featured