• Querying a date/time field

    Author
    Topic
    #475177

    Using <=Now()+30 to show me the next 30 days in a query. I am using this on a date/time field, formatted to 1/16/2010. For some reason when I query on this particular table it will not work. To get it to work I have to use a between #1/16/2010 # and #2/15/2010 #. I really don't want to go that route because I will have to change the date everytime it's run. Is there something else I can use? Is it a formatting issue with the field? Thanks.

    Viewing 3 reply threads
    Author
    Replies
    • #1270033

      What do you mean by “does not work?”
      Does it produce an error? return too many results? too few results?

      Now() returns the current date and time, Date() returns just the current date. That is why my previous post suggested the Date() function.
      The Time component will add extra digits after the decimal point, and so could change the results returned a little.

    • #1270034

      You need to use the DateAdd function. Something like this should work:

      <=DateAdd("d",+30,Now()))

      • #1270036

        You need to use the DateAdd function. Something like this should work:

        <=DateAdd("d",+30,Now()))

        Dates are stored in Access just as numbers, so you can use the DateAdd function, but to add a number of days you can just also use plain arithmetic.

        • #1270095

          Dates are stored in Access just as numbers, so you can use the DateAdd function, but to add a number of days you can just also use plain arithmetic.

          Hi,

          Maybe so, I won’t deny it, but after using a few DBs and languages and getting some issues sometimes, I have resorted to a common, always working strategy – use the date handling functions to perform date calculations.

    • #1270035

      By not work I should clarify. I mean it will show all the 2010 data not the next 30 days that I am looking for. I tried <=DateAdd("d",+30,Now()) . It gave me all tha data for 2010. Any other solutions? Thanks so much..

    • #1270037

      Do you mean all the 2011 Dates? Did you put in the extra test to exclude dates that have come and gone?

      You need =Date() to exclude past dates.

    Viewing 3 reply threads
    Reply To: Querying a date/time field

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: