Results 1 to 9 of 9
  1. #1
    Sck is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jul 2010
    Posts
    82

    Date range in specific month query

    I thought this would be easier, but I just can't work it out.



    I have a table with records that have a Start Date and End Date fields. I need to pull all records that happen at some point during a specific month.

    Example: Need all records that span some part of March 2022

    Results sample:
    Record 1 Start 2/25/22 and end 3/1/22
    Record 2 Start 3/28/22 and end 4/15/22
    Record 3 Start 2/25/22 and end 4/10/22
    Record 4 Start 3/5/22 and end 3/11/22

    I could write a VBA function to loop through the date range and if month value for any of the dates is March (3) and year value is 2022 then say true and include it but I have found functions like this are very slow to produce query results.

    Any thoughts? I really think I am making it harder than it needs to be, but I am just not seeing it.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,526
    functions are slow, so Cant you make a form and put 2 textboxes on it txtStartDate, txtEndDate

    select * from table where Between [Forms]![fDateRng]![txtStartDate] And [Forms]![fDateRng]![txtEndDate]

    or even use just the year
    ...where year([dateFld)) = [Forms]![fDateRng]![txtYear]

  3. #3
    Sck is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jul 2010
    Posts
    82
    Quote Originally Posted by ranman256 View Post
    functions are slow, so Cant you make a form and put 2 textboxes on it txtStartDate, txtEndDate

    select * from table where Between [Forms]![fDateRng]![txtStartDate] And [Forms]![fDateRng]![txtEndDate]

    or even use just the year
    ...where year([dateFld)) = [Forms]![fDateRng]![txtYear]
    I could but that may not get everything. if the record start date is 2/28/22 and end date is 4/1/22 and the person selected March (3/1 to 3/31) the record would not be included My issue is I need to pull the record if any day between the start and end is in March, I need the record. Just looking at start and end is not getting me there (I don't think)

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,122
    Review this thread and you should have your answer:
    https://stackoverflow.com/questions/...ranges-overlap
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Sck is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jul 2010
    Posts
    82
    think i found it in another post on the forum The following seems to work. THANKS

    (StartDate1 <= EndDate2) and (EndDate1 >= StartDate2)



  6. #6
    Sck is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jul 2010
    Posts
    82
    Thanks Gicu found the same post they were a lot more detailed than I needed for this application as I know the start and end dates in both ranges will be fully populated and in the correct order (starts < ends)

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,122
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    Join Date
    Jan 2021
    Location
    Missouri Ozarks, USA
    Posts
    19
    Hi Sck,

    I am trying to understand your problem using set theory. You have a "set of records" with start and end dates. If I understand it right, you want to filter them using a "timeline" which is a conditional "WHERE" clause. Is that right?

  9. #9
    Sck is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Jul 2010
    Posts
    82
    correct basically trying to find any records where the start and end dates overlap in any way the start and end of a specific month

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

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2018, 10:39 AM
  2. Replies: 43
    Last Post: 08-06-2014, 08:21 PM
  3. Replies: 7
    Last Post: 12-30-2013, 09:53 AM
  4. Date Range Query Only Returns Month and Day
    By hammer187 in forum Queries
    Replies: 5
    Last Post: 09-18-2012, 11:25 AM
  5. SELECT a specific DATE RANGE in Query
    By taimysho0 in forum Queries
    Replies: 28
    Last Post: 06-04-2012, 04:58 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
  •  
Other Forums: Microsoft Office Forums