Results 1 to 8 of 8
  1. #1
    jasonm is offline Novice
    Windows Vista Access 2003
    Join Date
    Oct 2012
    Posts
    22

    Year to Date Last Year - need query based on date field.


    I am a beginner so please keep it simple!!

    I have a date field. I need a query that will give me the records that fall between the start of last year (January 1, 2014) and today's date but last year (June 7, 2014).

    So today is June 7, 2015. I need to find the records with a date between January 1, 2014 to June 7, 2014.

    Thanks for your help.

    J

  2. #2
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    In the query design grid, try BETWEEN #01/01/2014# AND DATEADD("yyyy",-1,(DATE())
    Not sure what the effect leap years would have on your results.

  3. #3
    jasonm is offline Novice
    Windows Vista Access 2003
    Join Date
    Oct 2012
    Posts
    22
    Thanks for the quick response.

    I didnt really want to hardcode in #01/01/2014#. How else could I do that?

    BTW I dont really care about leap years - wont have a major effect on the numbers.

  4. #4
    jasonm is offline Novice
    Windows Vista Access 2003
    Join Date
    Oct 2012
    Posts
    22
    Also in the DATEADD part it seems like we are missing a bracket.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    Then what date if not 01/01/2014 as you requested? Will it always be Jan. 01 of the previous year? Will it be something that a user enters into a textbox control? Picks from a combo box list? You are correct - one more ) at the end.
    Last edited by Micron; 06-07-2015 at 08:50 PM. Reason: missing bracket

  6. #6
    jasonm is offline Novice
    Windows Vista Access 2003
    Join Date
    Oct 2012
    Posts
    22
    Sorry. Yes it will always be January 1 of the previous year.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,799
    BETWEEN DateSerial(DATEADD("yyyy",-1,DATE()),01,01) AND DATEADD("yyyy",-1,DATE())

    I don't think the bracket before DATE() was required, so I did not add the bracket that was "missing". Hope I got it right.
    TechOnTheNet is my go-to place for functions, especially for date/time ones.

  8. #8
    IrogSinta is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    103
    Correction on the DateSerial portion:
    BETWEEN DateSerial(Year(DATE())-1, 1, 1) AND DATEADD("yyyy",-1,DATE())

    Ron

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

Similar Threads

  1. Replies: 2
    Last Post: 04-25-2014, 11:33 PM
  2. Replies: 7
    Last Post: 11-06-2013, 09:51 AM
  3. Replies: 4
    Last Post: 01-09-2013, 11:16 AM
  4. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  5. Use field value as the year in a date
    By Eveline in forum Queries
    Replies: 1
    Last Post: 03-11-2010, 10:58 AM

Tags for this Thread

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