Results 1 to 10 of 10
  1. #1
    Tigerweld is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    6

    Between date and time

    I'm having trouble creating a 'between date and time' query. The times will always be the same, but the dates will vary so I will need to be able to input the start and end date, preferably with a date picker.




    Example:

    Start Jan 12, 2016 5:00:01PM
    End Jan 15, 2016 10:00:00 AM

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    To use date picker will have to build a form with controls for the date inputs. Then query can concatenate:

    SELECT * FROM table WHERE [datefield] BETWEEN Forms!formname!tbxStart & " 5:00:01 PM" AND Forms!formname!tbxEnd & " 10:00:00 AM";
    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.

  3. #3
    Tigerweld is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    6
    I get This expression is typed incorrectly, or it is too complex to be evaluated.

    WHERE (((Remosit.Date) Between [Forms]![Holidays]![txtStartDate] & "5:00:01 PM" And [Forms]![Holidays]![txtEndDate] & "10:00:00 AM"))

  4. #4
    Tigerweld is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    6
    oh wait, now I know why that is wrong, there isn't a time stamp in that field in the table, but in another field called "Time Processed" How would I add that to the query?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Look at my example again. Concatenation of time needs a space after quote mark in front of the time part.

    So date and time parts are in separate fields? Try:

    WHERE [Date] + [Time Processed] BETWEEN [Forms]![Holidays]![txtStartDate] & " 5:00:01 PM" And [Forms]![Holidays]![txtEndDate] & " 10:00:00 AM"


    Date is a reserved word. Should not use reserved words as names. Also, advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    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.

  6. #6
    Tigerweld is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    6
    I changed the name of the date field, but it still isn't working. When I run the query it's pulling in times before 5:00pm on the start date.

    WHERE ((([TransDate]+[Time Processed]) Between [Forms]![Holidays]![txtStartDate] & " 5:00:01 PM" And [Forms]![Holidays]![txtEndDate] & " 10:00:00 AM"))

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Don't know why.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  8. #8
    Tigerweld is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    6

    db is attached

    The query in question is the qryTime_Holidays
    Attached Files Attached Files

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,641
    Still shows Date as field name in table.

    Should first label on Holidays form say "First Day Worked"?

    The query is not recognizing the expressions as a date/time value.

    Expr1: CDate([Date]+[Time Processed])

    Between CDate([Forms]![Holidays]![txtStartDate] & " 5:00:01 PM") And CDate([Forms]![Holidays]![txtEndDate] & " 10:00:00 AM")
    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.

  10. #10
    Tigerweld is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    6
    That worked like a charm. I understand the query now. thanks!

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

Similar Threads

  1. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  2. Subtracting a date/time field from a number to get date/time
    By Lifeseeker1019 in forum Programming
    Replies: 4
    Last Post: 03-28-2014, 12:59 PM
  3. Replies: 1
    Last Post: 03-13-2014, 07:23 PM
  4. Replies: 4
    Last Post: 03-06-2013, 02:32 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