Results 1 to 5 of 5
  1. #1
    Rustin788 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    47

    Query to find records from only 6 months ago.

    Hey,



    I am trying to setup a query that will give me the records for 6 months back from the current day and only the records that were in that 6th month. So I guess say a month equals 30 days so I want records from between 181 days ago and 150 days ago. I want to always be that date range so the records should be changing daily. I know there is an option to separate by actual month in a date field but then the numbers will always be off depending on what part of the month it is.

    Thanks in advance to anyone that can help me out.

    *I will also be doing this for other months but I once the correct formula is implemented I imagine it will be easy to change it to fit the correct range.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try:

    SELECT * FROM table WHERE [date field] BETWEEN DateAdd("m",-6,Date()) AND Date();

    or

    SELECT * FROM table WHERE [date field] BETWEEN Date()-181 AND Date();

    or

    SELECT * FROM table WHERE [date field] BETWEEN DateAdd("d",-181,Date()) AND Date();
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Rustin788 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    47
    Hey,
    That gave me blank results. Previously I had:
    >=DateAdd("m",-6,Date())
    and without the >= I would get blank results as well. I tried inputting the >= into the formula you gave but it did not give any results either.


    *Just saw your update I will try those out as well.

    **The middle one you posted works but it is pretty much the same thing I posted above and it shows all records from the past 6 months.

  4. #4
    Rustin788 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2014
    Posts
    47
    Ok. I input the criteria below and I believe it is pulling up what I want. Thanks.

    [InvoiceDate] Between DateAdd("d",-181,Date()) And DateAdd("d",-150,Date())

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Glad you figured it out. I missed a couple details of your criteria.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 02-23-2014, 02:06 PM
  2. Replies: 8
    Last Post: 07-11-2013, 07:24 AM
  3. Replies: 10
    Last Post: 11-17-2012, 12:38 AM
  4. Query to find all records after a certain date
    By Matt Parsons in forum Queries
    Replies: 2
    Last Post: 08-24-2011, 06:22 AM
  5. Find Records Query
    By sullyman in forum Programming
    Replies: 1
    Last Post: 10-28-2009, 08:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums