Results 1 to 7 of 7
  1. #1
    Archer's Avatar
    Archer is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2019
    Location
    Down Under
    Posts
    16

    Query to extract time only from date/time fields

    Hi all.

    Tried to find an answer to this one via the advanced search but came up empty handed. I want to extract records from a table based on time values only, i.e. >=12:00 and <=18:00 from a date/time field stored as dd/mm/yyyy hh:nn.



    Can anyone advise please?

    thanks in advance.

  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,521
    Check out the TimeValue() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    Maybe
    DatePart("h",[someDate])>=8 And DatePart("h",[someDate])<=18
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Archer's Avatar
    Archer is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2019
    Location
    Down Under
    Posts
    16
    Quote Originally Posted by pbaldy View Post
    Check out the TimeValue() function.
    Yes i've used that which provides a new column that returns only time values, however when I try to enter criteria >="12:00" And <="18:00" the query is only returning values starting with 12:. Is my syntax criteria incorrect?

  5. #5
    Archer's Avatar
    Archer is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2019
    Location
    Down Under
    Posts
    16
    Quote Originally Posted by Micron View Post
    Maybe
    DatePart("h",[someDate])>=8 And DatePart("h",[someDate])<=18
    That worked nicely.
    Thankyou

  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,521
    Quote Originally Posted by Archer View Post
    Yes i've used that which provides a new column that returns only time values, however when I try to enter criteria >="12:00" And <="18:00" the query is only returning values starting with 12:. Is my syntax criteria incorrect?
    The delimiter for date/time values is #, not ".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    UR welcome. Did you try Paul's suggestion with #?

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

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2018, 04:58 PM
  2. Replies: 3
    Last Post: 12-16-2015, 06:43 PM
  3. Replies: 1
    Last Post: 04-01-2015, 01:29 AM
  4. Replies: 3
    Last Post: 08-20-2014, 01:47 PM
  5. Replies: 1
    Last Post: 03-13-2014, 07:23 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