Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Selecting records 11 months prior to StartDate

Posted on 2014-02-11
11
Medium Priority
?
303 Views
Last Modified: 2014-02-11
Hi Experts

I have created a query with the following criteria and based on a table with the fields [StartDate] and [EndDate]…

Between DateAdd("m",-11,[StartDate]) And DateAdd("m",-1,[EndDate])

If I set the [StartDate] on 01/01/2014 and the [EndDate] on 31/01/2014, I get the correct records returned starting 01/02/2013 to the 31/12/2013 (11 months). However, if I set the [StartDate] to 01/02/2014 and [EndDate] to 28/02/2014 my query will only return those records from the 01/03/2014 to the 28/01/2014.

I would really appreciate some help on how to change the criteria to include records to the last day of the month for the [EndDate] (31/01/2014)? I've searched extensively and can't find anything that is helping.

Thanks
darls15
0
Comment
Question by:darls15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39852229
try this criteria


Between dateserial(Year([StartDate]), Month([StartDate])-11,Day([StartDate]) And dateserial(Year([EndDate]),Month([EndDate])-1,Day([EndDate]))
0
 
LVL 10

Accepted Solution

by:
Gozreh earned 1000 total points
ID: 39852249
is your EndDate always the last day of the month ?  
if yes you can use "Between DateSerial(Year([StartDate]), Month([StartDate])-11,Day([StartDate]) And DateSerial(Year([EndDate]),Month([EndDate]),1)-1"
0
 

Author Comment

by:darls15
ID: 39852276
@Rey, thank you, however your query returned the only the records to the 24/01/2014. also, i placed a closing bracket before the And statement to get it to work, hope this was correct.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:darls15
ID: 39852281
hi gozreh, i've tested your solution and it works as i need it to. i also needed to put a closing bracket before the And statement. thank you.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39852282
sorry, typo missing ")"

Between dateserial(Year([StartDate]), Month([StartDate])-11,Day([StartDate])) And dateserial(Year([EndDate]),Month([EndDate])-1,Day([EndDate]))


what are the startDate and EndDate that you selected?
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39852288
DateSerial(Year([EndDate]),Month([EndDate]),1)-1  this will always give the last date of the previous month.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39852293
to get the last date of the Previous month, the syntax is

DateSerial(Year([EndDate]),Month([EndDate]),0)
0
 

Author Comment

by:darls15
ID: 39852295
hi rey, i set the [StartDate] to 01/02/2014 and [EndDate] to 28/02/2014. i tried this again and it is still only returning records from 01/03/2013 to 28/01/2014.
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 39852307
try this


Between dateserial(Year([StartDate]), Month([StartDate])-11,Day([StartDate])) And DateSerial(Year([EndDate]),Month([EndDate]),0)
0
 

Author Closing Comment

by:darls15
ID: 39852335
thank you both. i have given equal points to both your solutions as both will be helpful to me. your help is appreciated.
0
 
LVL 10

Expert Comment

by:Gozreh
ID: 39852353
For your example if you need 11 months prior to date, you don't need a start date and end date, you can use = Between DateSerial(Year(Date()),Month(Date())-11,1) And DateSerial(Year(Date()),Month(Date()),0)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question