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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get last 12 months date

Status
Not open for further replies.

ping99

Technical User
Mar 16, 2006
45
CA
Hi all,

I would like to get last 12 months date for example:
200609 to have 200506. ( year and month only )

I have tried this :

year(now -360) & month(now - 12) gave me
2005-3 instead of 200506

Please assist or guide me.

TIA
 
I don't quite get how "200506" is the "last 12 months" before "200609". Wouldn't it be "2005[red]09[/red]"?

There are several possibilities
Code:
Last12Months = DateAdd ("yyyy", -1, #2006/09#) [red]OR[/red]
Last12Months = DateAdd ("m", -12, #2006/09#)   [red]OR[/red]
Last12Months = DateAdd ("d", -365, #2006/09#)  [red]OR[/red]
Last12Months = DateSerial (2006, 9, -364)      [red]OR[/red]
Last12Months = DateSerial (2006, 9 - 12, 1)    [red]OR[/red]
Last12Months = DateSerial (2006 - 1, 9, 1)
and then
Code:
Format(Last12Months, "yyyymm")

 
Thanks Golom,

You are right for 200509 not 200506, your codes worked fine but I also tried this simple way, it works too.

Year(Now - 330) & IIf(Month(Now - 330) > 0 And Month(Now - 330) <= 9, "0" & Month(Now - 330), Month(Now - 330))
 
this simple way
You really think so ?
What about this ?
100 * (Year(Now) - 1) + Month(Now)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top