473,804 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weekday function - 'between this Tuesday and Last Tuesday'

I've hit a snag - I know this is easy, but the logic is escaping me. I
need to set criteria in a query to find dates in a date field that lie
between Tuesday of the current week and Tuesday of the previous week.
Any suggestions would be appreciated.

Thanks
Dave

Feb 8 '07 #1
4 6704
On Feb 8, 3:38 pm, dgmo...@erols.c om wrote:
I've hit a snag - I know this is easy, but the logic is escaping me. I
need to set criteria in a query to find dates in a date field that lie
between Tuesday of the current week and Tuesday of the previous week.
Any suggestions would be appreciated.

Thanks
Dave

See:

http://groups.google.com/group/comp....ee3a7c7ac10abf

for a way to get the date of the beginning of the week (untested).
Call it dtX.

After that, you'll want the date of the Tuesday on or after that
date. From my GEDay function applied to Tuesday (air code),

dtTues = DateAdd("d", (10 - WeekDay(dtX)) Mod 7, dtX)

Then you'll need the date of the Tuesday one week prior to that:

dtPrevTues = DateAdd("d", -7, dtTues)

I hope this helps,

James A. Fortune
CD********@Fort uneJames.com

Feb 8 '07 #2
On Feb 8, 4:46 pm, CDMAPos...@Fort uneJames.com wrote:
On Feb 8, 3:38 pm, dgmo...@erols.c om wrote:
I've hit a snag - I know this is easy, but the logic is escaping me. I
need to set criteria in a query to find dates in a date field that lie
between Tuesday of the current week and Tuesday of the previous week.
Any suggestions would be appreciated.
Thanks
Dave

See:

http://groups.google.com/group/comp..../msg/1aee3a7c7...

for a way to get the date of the beginning of the week (untested).
Call it dtX.

After that, you'll want the date of the Tuesday on or after that
date. From my GEDay function applied to Tuesday (air code),

dtTues = DateAdd("d", (10 - WeekDay(dtX)) Mod 7, dtX)

Then you'll need the date of the Tuesday one week prior to that:

dtPrevTues = DateAdd("d", -7, dtTues)

I hope this helps,

James A. Fortune
CDMAPos...@Fort uneJames.com
You can also use my LEDay function to get the date of the first day of
the week.

Public Function LEDay(dtX As Date, vbDay As Integer) As Date
LEDay = DateAdd("d", -(7 + WeekDay(dtX) - vbDay) Mod 7, dtX)
End Function

Replace vbDay with the Weekday number of the day the week starts on.

Sunday = 1
....
Saturday = 7

Example:

Week starts on Monday
Monday = 2
dtStartOfWeek = DateAdd("d", -(5 + WeekDay(dtIn)) Mod 7, dtIn)

dtIn = #2/8/07#
MsgBox(DateAdd( "d", -(5 + WeekDay(dtIn)) Mod 7, dtIn)) =2/5/2007

James A. Fortune
CD********@Fort uneJames.com

Feb 8 '07 #3

Tuesday of this week is always equal to

TuesdayDate = date() - (datepart("w",d ate()) - (3 -
Datepart("w",da te())))

PriorWednesdayD ate = TuesdayDate - 6

then the criteria will be

between PriorWednesdayd ate and TuesdayDate

The between function includes the equal condition for the two end
dates. If you subtracted 7 then the Tuesday dates would be included in
last weeks. search AND in this weeks search - you would have 8 days of
activity not 7 days.
explanation:
datepart("w",da tefield) will supply the day of the week relative to
Sunday being day 1
therefore Tuesday is always 3.
If the day is Sunday or Monday the math will add days to the date.
If the day is tuesday the math will subtract days from the date to
always land on Tuesday.
If the day is Tuesday, the math doesn't change the date.

Ron

Feb 8 '07 #4
On Feb 8, 5:40 pm, "Ron2006" <ronne...@hotma il.comwrote:
Tuesday of this week is always equal to

TuesdayDate = date() - (datepart("w",d ate()) - (3 -
Datepart("w",da te())))

PriorWednesdayD ate = TuesdayDate - 6

then the criteria will be

between PriorWednesdayd ate and TuesdayDate

The between function includes the equal condition for the two end
dates. If you subtracted 7 then the Tuesday dates would be included in
last weeks. search AND in this weeks search - you would have 8 days of
activity not 7 days.

explanation:
datepart("w",da tefield) will supply the day of the week relative to
Sunday being day 1
therefore Tuesday is always 3.
If the day is Sunday or Monday the math will add days to the date.
If the day is tuesday the math will subtract days from the date to
always land on Tuesday.
If the day is Tuesday, the math doesn't change the date.

Ron

All great answers, Gents - thanks a lot!
Dave

Feb 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
11250
by: dr. zoidberg | last post by:
Hello, I have this: Mon, Tue, Wed, Thu, Fri, Sat, Sun created as links. What I would like to do is to associate days with its current week dates, for example: Mon (05.01.2004); Tue (06.01.2004); and so on. TNX
2
6616
by: David Morgan | last post by:
Hi Hopefully the subject says it all. Given a weekday, (1 to 7) and an occurrence with in a month, (1 to 4), I need to ascertain the date on which it first occurs in any given month and year. For example, what is the date of the third Tuesday in October 2004. Has anyone done this before? Would be grateful for some assistance.
1
2030
by: Kd | last post by:
I am currently using a form with Weekdays Mon Tues Wed Thur Fri This is generated by a table that the days are being entered manually I would like to create a form that the days updated themselves by 7 days each time a new record is opened. Any and all thought are appreciated
2
2946
by: rf | last post by:
Hey I need to be able to get the dates from last wednesday to the past tuesday on thursday or friday every week. How would I do that? For example: m t W TH F M T w th f I would need the dates of the CAPITAL W and T when I run the script from the last th or f
14
2135
by: Divit | last post by:
I want my code to tell me that (today) April 12th is the second wednesday of the month. And only thing I can find is the function to tell me what date belongs to the 2nd day in a given month and year. Please help regards ScuBart
6
7651
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
2
3145
by: MLH | last post by:
With a table of holidays and A97's date fn's - how best to count weekends and holidays between two dates? My holiday table has 4 fields. I will be adding records to it each year as info becomes known. What approach would you advise to tally up the number of holidays, saturdays and sundays between any 2 dates in the range of my records in this table?
9
7828
by: Dave | last post by:
What is the C# Equivalent to VB's Weekday function? I'm trying to convert this: Select Case Weekday(CurrentDate) Case 1 ' Sunday WKG = CurrentDate Case 2 ' Monday WKG = CurrentDate + 6 Case 3 ' Tuesday WKG = CurrentDate + 5
6
2563
RamananKalirajan
by: RamananKalirajan | last post by:
Can any one please help me out in calculating the no of weekdays between two givendays using Javascripts I tried in many way but I cant get the solution. The date format I am using is DD-MON-YYYY. Please help me out
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.