getting values from last month

  • Thread starter Thread starter Nelson
  • Start date Start date
N

Nelson

Hello,

I would like to run a query that will give me the entries
of a table from the previous month. The entry_date is in
the format of a simple date (ie., mm/dd/yyyy).

I've tried the DateAdd("m", -1, Now()), but I don't want
to see values that were entered in this month,and the
above expression returns values from the previous month
but only starting from 31 days ago, Ex, let's say today
is Jan.15, the entries returned will be from Dec.15 on
until today...which I don't want. I want all the entries
from Dec.1st to the 31st only.

Any help will be appreciated. Thank you in advance
 
Nelson said:
Hello,

I would like to run a query that will give me the entries
of a table from the previous month. The entry_date is in
the format of a simple date (ie., mm/dd/yyyy).

I've tried the DateAdd("m", -1, Now()), but I don't want
to see values that were entered in this month,and the
above expression returns values from the previous month
but only starting from 31 days ago, Ex, let's say today
is Jan.15, the entries returned will be from Dec.15 on
until today...which I don't want. I want all the entries
from Dec.1st to the 31st only.

Any help will be appreciated. Thank you in advance

WHERE entry_date >= DateSerial(Year(Date), Month(Date)-1,1)
AND entry_date < DateSerial(Year(Date), Month(Date),1)

Play around a bit with DateSerial. You would be amazed at the problems it
solves due to the way it works. For example the zeroth of a month returns
the last day of the previous month. Putting a value larger than 12 in for
the month automatically rolls you into the next year. Putting a day value
in that is greater than the month will hold automatically rolls you into
the next month.
 
Thank you very much, now I would like to do the same but
instead of last month's, I want last week's begining
Sunday and ending on Saturday!

Thank you once again.
 
Thank you very much, now I would like to do the same but
instead of last month's, I want last week's begining
Sunday and ending on Saturday!

SundayOf LastWeek: DateAdd("d", -Weekday(Date())-6, Date())

SaturdayOf LastWeek: DateAdd("d", -Weekday(Date()), Date())
 
Back
Top