Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Now-Luanda, Angola, Originally - Anna Bay, New South Wales, Australia
    Posts
    238
    Thanks
    0
    Thanked 0 Times in 0 Posts

    One year Ago (2003 allSPs/SBS 2003)

    A really dumb one:
    I want to have a query filter for records dated say, 1 year ago. ie Date()- 1 year or possible Date()-18months and cant work out how to do this
    TIA
    Steve
    Dummy from Down Under <img src=/S/flags/Australia.gif border=0 alt=Australia width=30 height=18>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: One year Ago (2003 allSPs/SBS 2003)

    You can use
    <code>
    DateAdd("yyyy",-1,Date())
    </code>
    as criteria. You can look up the DateAdd function in the VBA help for details about the arguments.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: One year Ago (2003 allSPs/SBS 2003)

    Another option is to use the DateSerial function in the query criteria.

    DateSerial(Year(Date)-1, Month(Date),Day(Date))

    The DateSerial function makes a Date from Year, Month and Day provided.

    In this case I am using the Year of the CurrentDate minus 1, the Month of the CurrentDate, and the Day of the CurrentDate.
    Regards
    John



  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: One year Ago (2003 allSPs/SBS 2003)

    There's a tiny difference if the current date is the 29th of February in a leap year. The DateAdd method will result in the 28th of February of the previous year, and the DateSerial method in the 1st of March. Depending on what you want, one or the other may be the preferred solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •