Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    ones_zero is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jan 2020
    Posts
    17

    Query data from two different date fields

    Hello


    I have a table that has two different date fields
    - Date Reported
    - Date Completed

    Currently i'm querying the data from the "Date Completed" field by using the criteria in the Date Completed query column Like "*" & [Enter Year] & "*"
    I'm only querying the year from the date field "Date Reported" The date format is for example 2/13/2021

    How can i add criteria to the "Date Reported" column to query this data by the year in the "Date Reported" column.

    When I query this data "Building Issues" i'd like to query this data by the year from the columns "Date Reported" and 'Date Completed"
    Click image for larger version. 

Name:	Date Completed.JPG 
Views:	16 
Size:	17.5 KB 
ID:	44228Click image for larger version. 

Name:	Date Reported.JPG 
Views:	16 
Size:	16.0 KB 
ID:	44229Click image for larger version. 

Name:	Building issues.JPG 
Views:	16 
Size:	15.4 KB 
ID:	44230


    ​Thanks,

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    In the query,Add another field to filter on:
    Year([date completed])

    Put your parameter box there as criteria:
    [Enter year]

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,543
    ones_zero

    Not sure of your exact requirements. The attached example may help
    Attached Files Attached Files
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Is the data type of those two fields Date/Time or TEXT?

    Do you want Building_Issues AND Date_Reported = 2020 AND Date_Completed = 2020?
    Code:
    SELECT tblWork_Tracker.Date_Completed, tblWork_Tracker.Date_Reported, tblWork_Tracker.Employee, tblWork_Tracker.Building_Issues
    FROM tblWork_Tracker
    WHERE (((tblWork_Tracker.Building_Issues)=Yes) AND ((Year([Date_Completed]))=[enter year]) AND ((Year([Date_Reported]))=[enter year]));
    Or

    Do you want Building_Issues AND (Date_Reported = 2020 OR Date_Completed = 2020)?
    Code:
    SELECT tblWork_Tracker.Date_Completed, tblWork_Tracker.Date_Reported, tblWork_Tracker.Employee, tblWork_Tracker.Building_Issues
    FROM tblWork_Tracker
    WHERE (((tblWork_Tracker.Building_Issues)=Yes) AND ((Year([Date_Completed]))=[enter year])) OR (((tblWork_Tracker.Building_Issues)=Yes) AND ((Year([Date_Reported]))=[enter year]));

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    to add an explanation, dates are stored as decimal numbers, what you see is a formatted view of that number.

    The bit before the decimal point is the number of days since 31/12/1899. The bit after is the time in number of seconds to now divided by 86400, the number of seconds in 24 hours

    so now is
    ?cdbl(now()) 44241.3880671296

    and you can covert a number to a date
    ?cdate(34567)
    21/08/1994
    ?cdate(34567.12345)
    21/08/1994 02:57:46

    - you can see your Like criteria won't work

    so you use the year function to get the year

    ?year(34567.12345)
    1994

  6. #6
    ones_zero is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jan 2020
    Posts
    17
    Ok let me make sure I understand.
    Since my goal is to query data from the “Building Issues” table by the Year only from the “Dates Reported” & “Dates Completed” columns in the table.
    - I would and this criteria under “Date Reported”? Year([date completed])

    - I currently have this criteria under “Date Completed” & it works. Like "*" & [Enter Year] & "*"
    I just need to also filter the Building Issues data by “Date Reported” by year only like I’m doing under Date Completed.

    That’s for your patience, I’m no Access expert but I’m learning

    Thanks again for helping

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    OK - I stand corrected re like - not a way I would go but it's your app

    with regards the rest, you need to answer the question Steve asked in post #4. Would also be courteous to try his suggestions and provide feedback

  8. #8
    ones_zero is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jan 2020
    Posts
    17
    Ok thanks..I will give it a try.
    Question, would I insert this in the criteria section of the query?

    SELECT tblWork_Tracker.Date_Completed, tblWork_Tracker.Date_Reported, tblWork_Tracker.Employee, tblWork_Tracker.Building_Issues
    FROM tblWork_Tracker
    WHERE (((tblWork_Tracker.Building_Issues)=Yes) AND ((Year([Date_Completed]))=[enter year]) AND ((Year([Date_Reported]))=[enter year]));

  9. #9
    ones_zero is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jan 2020
    Posts
    17
    I thought this would be simple as adding another Criteria filter under the "Date Reported" but I cant seem to get it working
    It needs to be AND to include both the "Date Reported" and "Date Completed" Year
    Maybe the Like "*" & [Enter Year] & "*" is not the best way to filter in the criteria, but im not sure how to pull the year from the dates from both
    thanks again for helping
    Click image for larger version. 

Name:	Query Building Issues.jpg 
Views:	12 
Size:	40.1 KB 
ID:	44243

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,424
    cant seem to get it working
    what does that actually mean?

    im not sure how to pull the year from the dates from both
    you've been shown a couple of times - use the year function

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Here is one simple way, add a new field like shown here:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	11 
Size:	9.6 KB 
ID:	44244
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    ones_zero is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jan 2020
    Posts
    17
    Gicu....I have been using you guys guidance.
    When I say I can’t get it to work that’s what I mean, I can’t get it working I’m doing something wrong...also when I say I’m no Access expert, that also means that you may have to be be more specific with your responses.

    I have asked how to insert the code from one of the above responses, but I’ve not been giving any guidance for this.

    All I know is how to add it to the criteria section of the query. Again I’m no Visual Basic or Access expert like you guys but I’m trying

    Sorry to bother you, but I appreciate your help and time

  13. #13
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    See image below:
    Click image for larger version. 

Name:	1zeropng.png 
Views:	9 
Size:	87.6 KB 
ID:	44245

    Edit: Looking closer at the image, which was copied from your post #9, indicates that it is a mashup, not an actual query image. Have you tried the actual query that the image represents? That works OK in my tests.

  14. #14
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Added important edit comment in post #13.

  15. #15
    ones_zero is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jan 2020
    Posts
    17
    Hello davegri
    If i remove the "Yes" which is a Yes/No Data type. I do receive data, but only by the year from the "Date Completed" column
    If I put Like "*" & [Enter Year] & "*" as the criteria under "Date Reported" and Like "*" & [Enter Year] & "*" in the ""Date Completed" criteria filter and add Yes back to the criteria under "Building Issues" so it would filter the year out of Date Reported and Date Completed for the query Building Issues.
    I dont receive any data results from this query.

    I have issues i guess understanding how to setup my query to filter the Year only by both the "Date Reported" and "Date Completed" columns in the Work_Tracker Table
    It will work if i try to only filter by one or the other but not by both

    Note: I've tried the query from the post#13 image and i receive No data back from the query and I know i should have data from year 2021 from the 'Date Reported" and the "Date Completed" columns
    I leave the Yes in the criteria for Building Issues to filter this data. It is a Yes/No data type. If i take Yes out, I still only receive data from the "Date Completed" column



    thanks,

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to total fields with no date data
    By mick2000 in forum Reports
    Replies: 2
    Last Post: 08-14-2020, 04:57 AM
  2. Replies: 2
    Last Post: 06-13-2018, 03:59 AM
  3. Replies: 4
    Last Post: 04-22-2015, 05:50 AM
  4. Replies: 5
    Last Post: 12-12-2013, 12:14 PM
  5. Replies: 12
    Last Post: 05-07-2012, 12:41 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