Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4681
  • Last Modified:

Display quarterly data - "rolling" quarter

User would like to see 3 months of data at a time. For example, today is 4/26/06. He would like to see all of February, March and April (to-date). When May rolls around, February will drop off and he would like to see March, April and May (to-date). Any ideas on how to accomplish this in a query? There is a field in the query called Close Date that I will use and need to add the search criteria to that.

Thanks!
0
khawkins96
Asked:
khawkins96
  • 2
  • 2
1 Solution
 
JohnK813Commented:
For 2/1/06 to 4/26/06:

SELECT * FROM YourTable WHERE CloseDate BETWEEN CDate(Month(Date())-2 & "/1/" & Year(Date())) AND Date()

For 2/26/06 to 4/26/06:

SELECT * FROM YourTable WHERE CloseDate BETWEEN DateAdd("m", -2, Date()) AND Date()
0
 
khawkins96Author Commented:
JohnK813, thank you for responding.

4/26/06 was just the example. I need it to be able to take today's date, Now(), and find the three months from there. Also, I would prefer not to have to "hard code" this. Is there another way of doing it?

Thanks.
0
 
JohnK813Commented:
Sorry, guess I was a little misleading.  What I was trying to say was that my first statement started at the 1st of the month two months ago, and my second statement started exactly 2 months ago.

Neither is "hard coded," though.  Date() is esentially the same as Now().  The only difference is that Date() just returns the current date, whereas Now() also returns the time.  So, if you replace Date() with Now() you should be set.

Some more explanation:

CDate(Month(Date())-2 & "/1/" & Year(Date()))
Month(Date())-2 takes the month of the current date and subtracts 2
Year(Date()) gets the year of the current date
CDate converts the month + /1/ (the day) + the year into date format

DateAdd("m", -2, Date())
Subtract two months (or, if you prefer, "add -2 months") to the current date.
0
 
khawkins96Author Commented:
Thanks for your help!
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now