Results 1 to 2 of 2
  1. #1
    tcarp is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2012
    Posts
    6

    Parameter Query Date/Time

    I need the criteria to run a parameter query for date AND time. Using the following works, but I need the time included as well:

    Between [Start Date] And [End Date]

    I was trying to get something like this to work:

    Between #[Start Date]12:01:00 AM# And #[End Date] 11:59:59 PM#

    When I manually input the date/time into the criteria box, it works fine, but I am building a macro to partially automate my process. My question is: can someone please provide me with an expression for a query that will prompt the user for the start date and end date, but will automatically include the time (as shown above). The user should only have to change the dates in the query. The time will never change.

    Thanks in advance!



    TCARP

  2. #2
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    First thing to remember is that date/time is held internally as a number, the integer part specifying the date and the decimal part specifying the time. I don't think it is necessary to add a time to the start date; I assume you mean midnight. You now want to add all 24 hours less 1 second to the end date. This actually leaves a one-second period between 11:59:59 pm and midnight that is not tested. Personally I would not use the 'Between' construct for this test but do it in two comparisons.

    MyDateTime >= CDate([Enter Start Date mdy]) AND MyDateTime < DateAdd("d", 1, CDate([Enter End Date mdy]))

    I've used the CDate function rather than the #...# delimiters.

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

Similar Threads

  1. Replies: 6
    Last Post: 02-28-2013, 05:38 PM
  2. Date and Time Query Off Of Form
    By Joopster in forum Queries
    Replies: 4
    Last Post: 02-19-2013, 08:01 PM
  3. Can I use a Parameter on a Date/Time Field?
    By Paul H in forum Queries
    Replies: 5
    Last Post: 04-24-2012, 03:12 PM
  4. Replies: 2
    Last Post: 04-24-2012, 01:26 PM
  5. Date/Time Field Query...
    By Coffee in forum Queries
    Replies: 5
    Last Post: 07-05-2011, 11:27 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