Solved

My WHERE Clause Using DatePart is Not Working the Way I Need it to

Posted on 2013-05-22
4
424 Views
Last Modified: 2013-05-22
I am using the following WHERE clause to attemp to pull only data from LAST WEEK from a table

WHERE DatePart("ww", [15th_St_Panel_Plant_FPY.ProductionDate]) = (DatePart("ww", Date())-1) AND DatePart("yyyy", [15th_St_Panel_Plant_FPY.ProductionDate]) = (DatePart("yyyy", Date()));


However, when I compare the query return to manually calculated data from Last Week, the numbers do not match.

The ProductionDate is in the format mm/dd/yyyy. The first day of the week is intended to be Sunday.

Is there something in my Syntax, or am I just wrong in trying to do it this way?
0
Comment
Question by:Rex85
  • 2
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39187990
try:

WHERE [ProductionDate] >= DateAdd("d", -weekday(Date())-6, Date())
AND [ProductionDate] < DateAdd("d", -Weekday(Date()) + 1, date())
0
 

Author Closing Comment

by:Rex85
ID: 39188012
That worked...Thanks!
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39188033
You may need to tweak the values of -6 and +1 to get the precise definition of "last week" that you are looking for.

Glad to help.
0
 

Author Comment

by:Rex85
ID: 39188453
Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now