Results 1 to 4 of 4
  1. #1
    Hawkeyesv is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    11

    Query for last 30 days

    I am trying to make a query to only show entires older than 30 days. I have tried >=date()-30, between functions, and datevalue()-30 but I always get the following error message: Data type mismatch in criteria expression.

    I will say when I sourced my excel spreadsheet to access I had to make an expression for the date to format properly (datevalue). Is this the reason why I’m getting this error? If so, how do I rectify it?

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    The message is telling you that there is a discrepancy between the criteria you built and the field when it comes to data types. If coming from Excel, your field might be text. No idea what this means
    I sourced my excel spreadsheet to access
    Try that again in more specific terms: you imported to a table? Linked to the sheet? Something else?

    You might have to use CDate() on the field or wrap your date(s) in date delimiters (e.g. #01/01/2020#).
    I had to make an expression for the date to format properly
    Note that formatting has no effect on the data type - only how it is shown. The exception is that if you use the Format function, it coerces the data to a string, so perhaps your criteria is a date (#01/01/2021#) but you've converted the field data to a string. I think that it would help if you posted your expression and the sql and cleared up some of the unknowns I've mentioned.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    use date math functions:

    datediff("d", [dateFld], Date()) > 30

  4. #4
    Hawkeyesv is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2021
    Posts
    11
    Quote Originally Posted by ranman256 View Post
    use date math functions:

    datediff("d", [dateFld], Date()) > 30
    Thank you so much, it worked!

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

Similar Threads

  1. Query with just business days?
    By Chuggers75 in forum Access
    Replies: 5
    Last Post: 04-12-2018, 07:42 AM
  2. Replies: 9
    Last Post: 03-07-2016, 04:17 PM
  3. Replies: 2
    Last Post: 04-10-2015, 03:51 AM
  4. Over 60 Days Query
    By sandy budd in forum Queries
    Replies: 13
    Last Post: 03-08-2012, 09:27 AM
  5. Select Dates between days and two days ago?
    By rstonehouse in forum Queries
    Replies: 4
    Last Post: 08-18-2010, 02:13 AM

Tags for this Thread

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