Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2004
    Posts
    26

    Unanswered: Data for Last Month

    Hello,

    I have a query which pulls data based on a date range.
    However, instead of using this, I'd like to only get data for last month.

    I have tried doing this by adding 2 fields :

    Code:
    Month: Month(myDate)
    
    and
    
    Year : Year(myDate)
    In each of these fields I have added a criteria of :

    Code:
    Month(Date())-1
    
    and
    
    Year(Date())
    This allows me to get the data for last month (say February), but also ensures it is only the data for this year. (as the DB holds data for the past 4 or 5 years)

    The problem is though, when the year rolls over to January, this will not work.

    Can anyone shed any light on an alternative please ?

    Thanks,

    J.

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Work with your dates as dates. Lookup the functions DateDiff and DateAdd in the help file - those will help you setup the query.
    Code:
    DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
    
    
    DateAdd(interval, number, date)
    have fun!
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  3. #3
    Join Date
    Jun 2004
    Posts
    26
    Thanks very much - I'll look into that.

Posting Permissions

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