How to find a date six months ago

  • Thread starter Thread starter Frederick Wilson
  • Start date Start date
F

Frederick Wilson

Hello all,

I am trying to write a code for a command but so all the user has to do
is click it and it will give them the date six months ago from today.

I can not for the life of me figure this out. DateDiff needs two dates,
I only know one date which is today's or 'Date()'

I tried to parse out the parts of the date with month, years and day but
if you just slap on today's day you could wind up with 31 FEB which we
all know is not right.

Hmmm, What to do?

Thanks,
Fred
 
NewDate = DateAdd("m", -6, Date())
This subtracts six months from the current date.

TomU

TomU
 
I tried to parse out the parts of the date with month, years and day but
if you just slap on today's day you could wind up with 31 FEB which we
all know is not right.

Hmmm, What to do?

Two suggestions:

DateAdd("m", -6, Date())

DateSerial(Year(Date()), Month(Date()) - 6, Day(Date()))

These will return March 1 if run on September 30. DateSerial is in
fact quite clever about handling strange combinations of months and
days.

There *are* other date functions... try looking in the Help with the
VBA editor open to find them!

John W. Vinson[MVP]
 
Back
Top