Results 1 to 2 of 2
  1. #1
    JohnJohn is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Mar 2014
    Posts
    1

    Trouble Getting Date/Time Range - Date and Time Are Separate Fields


    Hi! I am having a hard time figuring this out and would be very grateful if anyone has any tips to point me in the right direction!

    I have a database with date and time each stored in a separate field. Now I want to query the database based on a start date/time and an end date/time. I started with the code below but it only returns events within the same time range on each day when what I really need is every event from a specified date and time through a specified date and time.

    Code:
    SELECT myTable.ID AS myTable_ID, myDate, myTime, FirstName, LastName
    FROM Staff INNER JOIN myTable ON
    Staff.ID = myTable.StaffID
    WHERE myTable.myDate >= #3/2/2014#
    AND myTable.myDate <= #3/3/2014#
    AND myTable.myTime >= #8:00PM#
    AND myTable.myTime <= #11:00PM#
    ORDER BY myDate desc
    In the above example what I want is every event from 3/2/2014 8:00PM until 3/3/2014 11:00PM. But what I get instead is every event between 8:00PM and 11:00PM on 3/2/2014 and every event between 8:00PM and 11:00PM on 3/3/2014.

    I should mention that this query will actually be used in an ASP website and not in Access but I am trying to use Access to get the query built properly.

    Thanks in advance for any assistance!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    This is why keeping date/time as a single value is better. Just about the only case where keeping data elements in one field is more convenient.

    Concatenate the fields.

    WHERE CDate(MyDate & MyTime) BETWEEN #3/2/2014 8:00:00 PM# AND #3/3/2014 11:00:00 PM#
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Selecting from specific Date and Time range
    By LindaRuble in forum Programming
    Replies: 1
    Last Post: 05-15-2013, 07:37 AM
  2. Replies: 4
    Last Post: 03-06-2013, 02:32 PM
  3. Trouble with date/time formatted as text...
    By fatboymedic in forum Import/Export Data
    Replies: 2
    Last Post: 09-25-2012, 10:34 AM
  4. Two Date/Time and Memo Fields
    By Luke in forum Access
    Replies: 3
    Last Post: 08-24-2011, 02:55 PM
  5. Replies: 6
    Last Post: 01-04-2011, 05:43 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