Simple query question on Date/Time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colintis
    Contributor
    • Mar 2010
    • 255

    Simple query question on Date/Time

    I'm fixing a query that takes date filter on specific date (e.g. 10/13/2010). The date field in the table source also contains time along with the date. (E.g. 13/10/2010 6:26:45 AM)

    On the where clause of the query, how can I filter the date with the standard short date format? I tried 2 of the followings but didn't work.
    Code:
    Method 1: WHERE Date = #10/13/2010#
    Method 2: WHERE Date BETWEEN #10/13/2010# AND #10/13/2010#
  • colintis
    Contributor
    • Mar 2010
    • 255

    #2
    Just used a longer method to solve this matter, I would appreciate to find a solution that is shorter than this.
    Code:
    WHERE Date BETWEEN #10/13/2010 00:00:00# AND #10/13/2010 23:59:59#

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      Simple answer is ... if you don't specify a time then Access assumes a time of 00:00 so when you say between 10/13/2010 and 10/13/2010 it assumes you mean between 10/13/2010 00:00 and 10/13/2010 00:00 so you get no results. The only two options are either to do what you are doing and give the times or to set the second date to be the day after. In other words to say between 10/13/2010 and 10/14/2010 which since it assumes a time of 00:00 for both dates will only return for the 10/13/2010.

      Hope that makes sense :)

      Mary

      Comment

      • colintis
        Contributor
        • Mar 2010
        • 255

        #4
        Yep, that makes sense to me, but would be it possible that the time at 10/14/2010 00:00:00 also included in the between result? I know that the chance of getting exactly that time is nearly impossible, but still curious to know. :P

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          I don't think so but you would have to test it to be sure. Set up a dummy record with that date and time and see if it shows up in the results.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32654

            #6
            I think you're looking for DateValue() :
            Code:
            WHERE (DateValue(Date) = #10/13/2010#)

            Comment

            • colintis
              Contributor
              • Mar 2010
              • 255

              #7
              Beautiful NeoPa, thank you :D

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32654

                #8
                Always a pleasure mate :-)

                Comment

                Working...