Results 1 to 4 of 4
  1. #1
    JNWT is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    2

    Check if date is within date range


    Hi I need some help here.

    I have a table A containing start_date and end_date, and a table B containing list of dates. What I want to do is to check between the start_date and end_date of table A, does it contain any of the dates listed in table B. If yes, count the number of dates in B that meet the criteria, else return 0

    start_date end_date Count the date
    20/4/2018 23/4/2018 2
    21/4/2018 25/4/2018 3
    20/4/2018 21/4/2018 1
    25/4/2018 28/4/2018 0

    date
    20/3/2018
    27/3/2018
    30/3/2018
    21/4/2018
    22/4/2018
    24/4/2018

    How can I get this?

    Please help. Thanks!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    make Q1, bring in both tables, do NOT join them
    fields: bring in t1.startdate ,Enddate and t2.Date
    in criteria under t2.Date, say: between t1.startdate and t1.Enddate
    run

    make Q2, count items in Q1.

  3. #3
    JNWT is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    2
    its working!

    Thanks so much for the help!

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,127
    Just to say it can be done in one query

    I've changed the Date field in T2 to Event_Date as Date is a reserved word

    As Ranman said put both tables in a query but don't join them
    Add your filter, click the Totals button to create an aggregate query
    Add Event Date again and select Count in the Group By row

    Code:
    SELECT Count(T2.Event_Date) AS CountOfEvent_Date, T1.Start_Date, T1.End_Date
    FROM T1, T2
    WHERE (((T2.Event_Date) Between [Start_Date] And [End_Date]))
    GROUP BY T1.Start_Date, T1.End_Date;
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 4
    Last Post: 11-20-2018, 11:57 PM
  2. Replies: 3
    Last Post: 01-26-2016, 01:56 PM
  3. Replies: 4
    Last Post: 02-03-2014, 12:16 PM
  4. Replies: 12
    Last Post: 01-23-2014, 03:24 PM
  5. Query to Pull from Date Range & Check 2 Areas
    By esh112288 in forum Queries
    Replies: 9
    Last Post: 11-12-2013, 10:05 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