Results 1 to 6 of 6
  1. #1
    Edward_ is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    38

    Query Date field Criteria question. Simple I'm sure. Ver 2002/2003

    I have a Time_On field where time/date is stored is this format: 5/21/2015 11:01:01 AM

    I'm trying to create a query, with the Criteria: Like "5/21/2015", (under 'Time_On') no records are found (when multiples of this date exists).

    So I created an expression in the query like this: Date: Format([Time_On],"Short Date"). This produces a nice field/column of date-only (ie. 5/21/2015). All ok.



    When I place a Like "5/21/2015" in the Critera of the Expression I get results.


    What syntax would I use to avoid the expression, and do the short date format in my criteria cell of Time_On? Is this possible?

    Any advice appreciated.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I think the way you're doing it is fine. You can also use the DateValue() function in a new field, or on your actual field a Between that uses the date alone and the date plus 11:59:59 PM (you can use the DateAdd() function to get there).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Edward_ is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    38
    Great, thanks pbaldy, I'll stay with the expression.

    By the way, could you suggest Criteria syntax for backdating one day?
    I'm testing this: DateAdd("d",-1,"Date") and Like "DateAdd("d",-1,"Date")". But I'm getting a Data type mismatch on these.

    I'll be using the SQL string from this in an automated VB application.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If you mean from "today", you don't want quotes around the Date() function:

    DateAdd("d",-1,Date())

    Access may remove the parentheses after Date, which is fine.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Edward_ is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    38
    That solved it!!
    Thanks for your time.

    Access left it as: DateAdd("d",-1,Date())

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 20
    Last Post: 01-13-2015, 02:23 PM
  2. Query with criteria a date field of a form
    By panoss in forum Queries
    Replies: 1
    Last Post: 12-22-2014, 09:03 AM
  3. Replies: 2
    Last Post: 06-09-2014, 11:23 AM
  4. Simple Date Criteria, Exclude Weekends
    By bigchicagobob in forum Queries
    Replies: 2
    Last Post: 04-28-2014, 09:37 PM
  5. Simple Date Format Question
    By EHittner in forum Queries
    Replies: 1
    Last Post: 03-10-2013, 04:46 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