Date formatting problem

  • Thread starter Thread starter Al
  • Start date Start date
A

Al

I am trying to use the following code to populate a
variable that is equal to 6 months ago from today's date.
TDay is declared as a Date.

TDay = Format(DATE, "Short Date")
TDay = TDay - 183

Even though my system clock has today's date correctly,
TDay is populated with the date: 12/13/2002. The
subtraction part works fine, I just can't figure out why
the date is incorrect. I got the problem part of the code
from the Access Help screen, which is also confusing.

Thaks in advance,
Al
 
I figured it out on my own. The following works:

TDay = Format(Now, "Short Date")
TDay = TDay - 183
 
You must have something in your database named DATE (a variable, a field in
a table, a control on a form, etc.)

Try to find it and rename it, and then see whether your original code works.
 
Al said:
I am trying to use the following code to populate a
variable that is equal to 6 months ago from today's date.
TDay is declared as a Date.

TDay = Format(DATE, "Short Date")
TDay = TDay - 183

Even though my system clock has today's date correctly,
TDay is populated with the date: 12/13/2002. The
subtraction part works fine, I just can't figure out why
the date is incorrect. I got the problem part of the code
from the Access Help screen, which is also confusing.

A better way to calculate that is:

TDay = DateAdd("m", -6, DATE)

I can't tell for sure, but it looks like you have a field or
a variable named DATE. If so, both you and Access are going
to be confused about whether you mean your own definition of
DATE or the built-in Date function.
 
Back
Top