Solved

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

Posted on 2013-05-22
4
464 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
[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
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye 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 48

Expert Comment

by:Dale Fye
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

ClickHouse in a General Analytical Workload

We have mentioned ClickHouse in some recent posts, where it showed excellent results.

In this article on Experts Exchange, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

623 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