Date Math

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Date Math

Post by Abraxus »

I need a query which shows me the data in my table where the date field is between last month and 24 months ago

For example, since today is 5/17/2011, I need date between 5/1/2009 and 4/30/2011.

The hard part is, I need it to be coded to do this no matter what month I run it in...so next month would be between 6/1/2009 and 5/31/2011.

Make sense?

I know how to do the most recent date [ DateSerial(Year(Date()), Month(Date()+1), 0) ] , just not the one 24 months ago.

Thanks!

Morgan
Morgan

User avatar
HansV
Administrator
Posts: 78464
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Date Math

Post by HansV »

Try

Between DateSerial(Year(Date())-2, Month(Date()), 1) And DateSerial(Year(Date()), Month(Date()), 0)

or

Between DateSerial(Year(Date())-2, Month(Date()), 1) And Date()-Day(Date())
Best wishes,
Hans