How to find a date six months ago

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
 
G

Guest

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

TomU

TomU
 
J

John Vinson

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top