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

x
?
Solved

Find out if a specific date is in the current week in Access query

Posted on 2013-05-20
3
Medium Priority
?
562 Views
Last Modified: 2013-05-20
Hi all.

How can I find out if a specific date is in the current week in an Access query? Basically, I'm working on a query that will display all sales orders except those whose [salesorderdate] is in the current week.

Is there a specific function for this?

Thank you in advance.
0
Comment
Question by:printmedia
[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
3 Comments
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 2000 total points
ID: 39181842
You can easily calculate the current week's date range using:

The first day of the current week (assuming Sunday = day 1):
Date() - WeekDay(Date()) + 1
The last day of the current week:
Date() - WeekDay(Date()) + 7


If you want everything before the current week then use:

Where [salesorderdate] < (Date() - WeekDay(Date()) + 1)

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39181880
You can use a query like this to show days in the current week:

SELECT Yourtable.YourDate
FROM Yourtable
WHERE ((([YourTable.YourDate]) Between DateAdd("d",-((Weekday(Date())-1)),Date()) And Date()));

There may be something a bit more elegant, but this will work
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39181920
<Is there a specific function for this?>
no, but you can make one

Here is a function based on the same expression
Public Function IsInCurrentWeek(YourDate As Date) As Boolean
    If YourDate >= DateAdd("d", -(Weekday(Date) - 1), Date) And YourDate <= Date Then
        IsInCurrentWeek = True
    Else
        IsInCurrentWeek = False
    End If
End Function

...Put this in a module, then call it in a query like this:

SELECT Yourtable.YourDate, IsInCurrentWeek([YourDate]) AS [Is In Current Week]
FROM Yourtable;

Returns True(-1) if the date IS in the current week, else it returns False.

Again, another expert may have something a bit more elegant, ...but this seems to work
Database109.mdb
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

609 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