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!

Access 97 DateAdd

Status
Not open for further replies.

RockyD

Programmer
Jul 25, 2001
8
0
0
US
This is probably a simple one, but I have an Access application that uses a valuation date and subracts 3 months and uses the resulting date for calculations. This has worked fine until this month where the valdate is now 2/28/02. The resulting calculation is 11/28/01. What am I doning wrong?? I thought Access would recognize February.

The code I am using is:

Dim Valdate as Date
Dim NewDate as Date

NewDate = DateAdd("m",-3,Valdate)

Again, this has worked fine until this month!!
 
You don't state it explicitly but are you looking for month-end dates, ie 11/30/01? It could easily be argued that 11/28/01 is the right answer based on the parameters in your dateadd call.

If your valuation date will always be the last day of a month(/quarter?) then this would work:

NewDate = DateAdd("d", -1, DateAdd("m",-3,dateadd("d",1,Valdate)))


Best Regards,
Mike
 
Hi!

It looks like Access is still doing what you have asked. If what you want is the last day of the month 3 months ago, then use this:

NewDate = DateSerial(Year(DateAdd("m",-3,Valdate)),Month(DateAdd("m",-2,Valdate)), 0)

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top