VB6 - Retrieving records that is 90 days old from today's date


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: VB6 - Retrieving records that is 90 days old from today's date

  1. #1
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60

    VB6 - Retrieving records that is 90 days old from today's date



    Hi all,
    My database/table is Access 2000 and the date format in the table is "mm/dd/yyyy"

    My objective is to retrieve all records that is 90 days old from today's date.

    I used this code:
    Code:
    & "WHERE tblUnclaimed.Original_Check_Date <= #" & DateAdd("d", -90, Date) & "# " _
    And my output included records from 2002 as well as 2007 which is wrong.

    What is the correct code/syntax?

    Thanks.
    Giftx.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by GiftX
    And my output included records from 2002 as well as 2007 which is wrong.
    Why is that wrong? Is not any date at all in either 2002 or 2007 greater than 90 days ago?

    The answer is yes, so in fact, the output is completely correct based on what you are asking for.

    Although you are getting what you are asking for, I suspect you are not getting what you want. So, perhaps you need to add an ADD clause to your query and stipulate a begin date so it does not go back into yesterday years.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Your code is fine, but you want records greater than or equal to 90 days ago:

    & "WHERE tblUnclaimed.Original_Check_Date => #" & DateAdd("d", -90, Date) & "# " _
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  4. #4
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    Dates >= a date 90 days ago gives you records that are 90 or less Days old.
    Dates <= a date 90 days ago gives you records that are 90 or more Days old, no matter how much older, 1 year, 2 years, 3 years, ect.
    Dates = a date 90 days ago gives you records that are exactly 90 days old.

    Without knowing what he is actually trying to do, it is difficult to suggest which option. If it is not one of the three above then a date range is probably what he needs.

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    A date range is, I believe, exactly what he needs.

    Something the is equal to, but not greater than, 90 days ago (which, for today, would be May 24th)

    So, I'm guessing he would want greater than or equal to 5/24 and less than or equal today.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  6. #6
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60
    Hi Hack,

    This is what I did:

    Code:
    Dim Todaydate As Date
    
    Todaydate = DateAdd("d", - 90, Date)
    When I ran the query, Todaydate = 5/23/2008.
    Then I plugged in "Todaydate" in my sql.
    
    Look at the hilited code within my sql. This code worked. It gave me 14 records - Records ranging from 5/29/2008 to 7/31/2008
    My Sql code:
    
    Code:
    strSQL = "SELECT tblUnclaimed.PassNumber, tblUnclaimed.EmployeeName, " _
    & "Original_Check_Number, Amount_of_Check, Original_Check_Date, " _
    & "EmployeeInfo.Status, tblL3Desc.L3, tblL3Desc.L3_Desc " _
    & "FROM (EmployeeInfo Right JOIN tblUnclaimed ON EmployeeInfo.L1 = tblUnclaimed.L1 " _
    & "AND EmployeeInfo.Pass_Number = tblUnclaimed.PassNumber) LEFT JOIN tblL3Desc " _
    & "ON EmployeeInfo.L1 = tblL3Desc.L1 AND EmployeeInfo.L3 = tblL3Desc.L3 " _
    & "AND EmployeeInfo.L5 = tblL3Desc.L5 " _
    & "WHERE tblUnclaimed.Original_Check_Date Between #" & Startdate & "# AND Now() " _
    & "AND tblUnclaimed.Status = 'U' ORDER BY tblL3Desc.L3, tblUnclaimed.PassNumber;"
    And that worked.

    Thanks.
    Giftx.

  7. #7
    Join Date
    Aug 2007
    Location
    NYC
    Posts
    60
    Resolved!

  8. #8
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    WHERE tblUnclaimed.Original_Check_Date Between #" & Startdate & "# AND Now() --- that is what did it for you, right?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. VB6 Date Picker
    By mattlucas in forum VB Classic
    Replies: 1
    Last Post: 03-02-2005, 10:08 AM
  2. How Do I Add 10 Days to A Date Column?
    By Chris in forum Database
    Replies: 1
    Last Post: 08-25-2002, 11:54 PM
  3. Date() - 60 days
    By Kyle in forum ASP.NET
    Replies: 5
    Last Post: 08-09-2001, 06:34 PM
  4. date + 3 days query
    By andy in forum Database
    Replies: 1
    Last Post: 02-05-2001, 02:08 PM
  5. Replies: 4
    Last Post: 11-27-2000, 12:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center