Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date problem with previous month

Status
Not open for further replies.

zclv05

Programmer
May 14, 2003
6
0
0
US
I tried using between dateserial to give me the first day of the previous month and last day of previos month.

eg. between #4/1/2003# and #4/30/2003#

The code I used is:
Between DateSerial(Year(Date()),Month(Date()-1),1) And DateSerial(Year(Date()),Month(Date()-1)+1,0)

I am getting back current data from 5/01/2003 - 5/14/2003

PLEASE HELP
 
your problem is: Month(Date()-1)

that's the month of yesterday

change it to: Month(Date())-1


rudy
 
Rudy, I change the statement to this:

Between DateSerial(Year(Date()),Month(Date())-1,1) And DateSerial(Year(Date()),Month(Date())-1+1,0)

I am getting previous month data but I am missing records with 4/30/03? Now what am I doing wrong?

Thanks for your help
 

your expression --

[tt]DateSerial(Year(Date()),Month(Date())-1,1)[/tt]

might give you trouble in january

in the expression --

[tt]DateSerial(Year(Date()),Month(Date())-1+1,0)[/tt]

the -1+1 seems superfluous, and i have no idea why the 0th of the current month works -- or doesn't

i would use DateAdd if i were going to do calculations on dates

in any case, if all you want is every date in the previous month, why not try this --

[tt]where year(yourtable.datecolumn)
= year(dateadd("m",-1,date())
and month(yourtable.datecolumn)
= month(dateadd("m",-1,date())[/tt]

that way you don't have to worry about finding the last day in the month

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top