query records only from 21 days after last date visited

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    query records only from 21 days after last date visited

    Hi, I have an access database with multiple users each with a unique profileid. Each has a last visited field in the database called "last visit" with the date stored like this. 02/07/2009 22:50:19

    I want only those users to appear on my page, for three weeks, after the date that they last visited.

    If anyone has any ideas that would be great.
    Thanks
    Richard
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Code:
    select * from profiles WHERE datediff(d, [last visit], getdate()) < 21
    I can't remember which direction this subtracts, it might need >21

    Jared

    Comment

    • fran7
      New Member
      • Jul 2006
      • 229

      #3
      Dear Jared, Thanks for that. I tried it but got an error Undefined function 'getdate' in expression.
      I then looked around and it seems access is not compatable with 'getdate'
      so I tried datediff(d, [latestvisit], " & now() & " < 21
      that seems to return todays date and time but I get an error (missing operator) in query expression at the expression. I tried now()) but the error is then on the second )
      Thanks if you have any ideas.
      Richard

      Comment

      • fran7
        New Member
        • Jul 2006
        • 229

        #4
        Hi, I think it might be
        datediff('d', [latestvisit], now()) < 21

        Tested a bit and it seems to work.
        Thanks very much for your great help.
        Richard

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          Originally posted by fran7
          Hi, I think it might be
          datediff('d', [latestvisit], now()) < 21

          Tested a bit and it seems to work.
          Thanks very much for your great help.
          Richard
          Glad you got it working. It's true, I switched away from access several years ago. I looked it up and it seems the access equivalent to "getdate" is just "date()", but if "now()" works as well, then I guess you are set.

          Jared

          Comment

          Working...