find day six month before

I

iccsi

I am looking for mechanism to find lthe day exacty 6 months before my
date time picker date.

For example, user select the date is May/15/2008 then I need find the
date Dec/15/2008.

It needs consider the year changed.

I tried to use Cdate(year(MyDatetime) & "/" & month(MyDatetime) - 6 &
"/" & Day(MyDatetime)), but it does not conisder year changed,


Your information is great appreciated,
 
D

Douglas J. Steele

DateAdd("m", -6, MyDatetime)

or

DateSerial(Year(MyDatetime), Month(MyDatetime) - 6, Day(MyDatetime))
 
I

iccsi

DateAdd("m", -6, MyDatetime)

or

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

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)










- Show quoted text -

Thanks millions for helping,
 
J

Jason

I see that 30 oct will generate 30th of February (not a valid date). Also
would Mydatetime being February actually generate the correct value for
August the year before?
 
D

Douglas J. Steele

Where do you "see" that?

First of all, six months prior to 30 Oct will be 30 Apr, but even if we're
talking eight months prior, the date functions take care of all that for
you.

Here's what I get in the Immediate Window:

?DateAdd("m", -8, #2008-10-30#)
2008-02-29
?DateAdd("m", -8, #2009-10-30#)
2009-02-28
?DateAdd("m", -6, #2008-02-15#)
2007-08-15
 

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