Weekly Date Calculation

P

Pam

Hi,
I have a report that returns a list of work done weekly. The expression I
am using now is only good for looking at the report on Monday (7 days
prior). Work week is Monday thru Sunday. Is there a calculation that will
give me the work completed and totaled from Monday to any day of that week.
Say if report was reviewed on Tuesday and then on Thursday, it would give
totals from Monday thru Tuesday and then again from Monday thru Thursday.
Here is what I am using now:

Between DateAdd("d",-6-Weekday(Date()),Date()) And
DateAdd("d",1-Weekday(Date()),Date())

Any help is greatly appreciated!
Thanks,
Pam
 
K

Klatuu

This function:
DateAdd("d",-6-Weekday(Date()),Date())
Actually returns a Sunday date, not a Monday.
This function will return the Monday date for the previous week:

dtmFromDate = DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

Then to get the To Date that will be the same day of the week one week prior
to today:

dmToDate = DateAdd("d",Weekday(Date,vbMonday)-1, dtmFromDate)
 
P

Pam

Klatuu,
Thank you for answering. The expression I listed in my first message is in
my query under StartTime criteria. Do I put the function you gave in the
same place? And do I combine them with "Between...And..."? If so, I tried
that and it returns an error message of "The expression you entered has an
invalid (dot) or ! operator or invalid parentheses" and the curser flashes
on the parenthesis before the "w".
Thanks again,
Pam
 
K

Klatuu

The function I sent to find the Monday should replace your query which is
returning Sunday instead of Monday, however, neither of the expressions
should be in the critera part of your query (assuming you are using the query
builder). The way to do this is to create two calculated fieds in your query
StartDate and EndDate
The Start Date field would have the name followed by " and then the
expression:

StartDate: DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

The End date woud be:

EndDate: DateAdd("d",Weekday(Date,vbMonday)-1, [StartDate])

The the Criteria field on your date field would be
BETWEEN [StartDate] AND [EndDate]

As to the error you got, be sure you copied the code correctly, I tested
these expressions in the immediate pane, so there should not be a syntax
problem.
 
P

Pam

I'm sorry, but I'm not doing something right. Okay, I have my query open in
design view. I go to next blank column and click Expression Builder icon.
The box opens and I type in your function StartDate:
DateAdd("d",vbMonday - DatePart("w", Date) -7, Date) and then do the same
for EndDate. Next, I go to MY date field, which is titled StartTime (date
and time field) and enter the criteria BETWEEN [StartDate] AND [EndDate].

Doing it this way, I'm prompted for vbMonday and Date parameter values.
When I enter thru those, I get "too complex" message.
If you would be so kind as to tell me what I'm doing wrong, I would
appreciate it.
Thanks,
Pam




Klatuu said:
The function I sent to find the Monday should replace your query which is
returning Sunday instead of Monday, however, neither of the expressions
should be in the critera part of your query (assuming you are using the
query
builder). The way to do this is to create two calculated fieds in your
query
StartDate and EndDate
The Start Date field would have the name followed by " and then the
expression:

StartDate: DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

The End date woud be:

EndDate: DateAdd("d",Weekday(Date,vbMonday)-1, [StartDate])

The the Criteria field on your date field would be
BETWEEN [StartDate] AND [EndDate]

As to the error you got, be sure you copied the code correctly, I tested
these expressions in the immediate pane, so there should not be a syntax
problem.


Pam said:
Klatuu,
Thank you for answering. The expression I listed in my first message is
in
my query under StartTime criteria. Do I put the function you gave in the
same place? And do I combine them with "Between...And..."? If so, I
tried
that and it returns an error message of "The expression you entered has
an
invalid (dot) or ! operator or invalid parentheses" and the curser
flashes
on the parenthesis before the "w".
Thanks again,
Pam
 
K

Klatuu

Doh!
Sorry, Jet doesn't understand Access constants. My bad.
You will need to use the literal value of vbMonday which is 2.
The for the Date, You will need to use Date().

StartDate: DateAdd("d", 2 - DatePart("w", Date()) -7, Date())
EndDate: DateAdd("d",Weekday(Date(), 1, [StartDate])

Another way to do this is to create hidden controls on your form that have
the expressions as their control source. then your criteria for StartTime
would be
BETWEEN "#" & Forms!MyFormName!StartDateControlName & "#" AND "#" &
Forms!MyFormName!EndDateControlName & "#"

Pam said:
I'm sorry, but I'm not doing something right. Okay, I have my query open in
design view. I go to next blank column and click Expression Builder icon.
The box opens and I type in your function StartDate:
DateAdd("d",vbMonday - DatePart("w", Date) -7, Date) and then do the same
for EndDate. Next, I go to MY date field, which is titled StartTime (date
and time field) and enter the criteria BETWEEN [StartDate] AND [EndDate].

Doing it this way, I'm prompted for vbMonday and Date parameter values.
When I enter thru those, I get "too complex" message.
If you would be so kind as to tell me what I'm doing wrong, I would
appreciate it.
Thanks,
Pam




Klatuu said:
The function I sent to find the Monday should replace your query which is
returning Sunday instead of Monday, however, neither of the expressions
should be in the critera part of your query (assuming you are using the
query
builder). The way to do this is to create two calculated fieds in your
query
StartDate and EndDate
The Start Date field would have the name followed by " and then the
expression:

StartDate: DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

The End date woud be:

EndDate: DateAdd("d",Weekday(Date,vbMonday)-1, [StartDate])

The the Criteria field on your date field would be
BETWEEN [StartDate] AND [EndDate]

As to the error you got, be sure you copied the code correctly, I tested
these expressions in the immediate pane, so there should not be a syntax
problem.


Pam said:
Klatuu,
Thank you for answering. The expression I listed in my first message is
in
my query under StartTime criteria. Do I put the function you gave in the
same place? And do I combine them with "Between...And..."? If so, I
tried
that and it returns an error message of "The expression you entered has
an
invalid (dot) or ! operator or invalid parentheses" and the curser
flashes
on the parenthesis before the "w".
Thanks again,
Pam


This function:
DateAdd("d",-6-Weekday(Date()),Date())
Actually returns a Sunday date, not a Monday.
This function will return the Monday date for the previous week:

dtmFromDate = DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

Then to get the To Date that will be the same day of the week one week
prior
to today:

dmToDate = DateAdd("d",Weekday(Date,vbMonday)-1, dtmFromDate)

:

Hi,
I have a report that returns a list of work done weekly. The
expression
I
am using now is only good for looking at the report on Monday (7 days
prior). Work week is Monday thru Sunday. Is there a calculation that
will
give me the work completed and totaled from Monday to any day of that
week.
Say if report was reviewed on Tuesday and then on Thursday, it would
give
totals from Monday thru Tuesday and then again from Monday thru
Thursday.
Here is what I am using now:

Between DateAdd("d",-6-Weekday(Date()),Date()) And
DateAdd("d",1-Weekday(Date()),Date())

Any help is greatly appreciated!
Thanks,
Pam
 
P

Pam

Okay, I entered the two function lines you listed below and put each in a
column on the query. EndDate gives error msg "The expression you entered
has a function containing the wrong number of arguments." I find the date
functions to be the most difficult to decipher, so I'm not sure what to do
with it.


Klatuu said:
Doh!
Sorry, Jet doesn't understand Access constants. My bad.
You will need to use the literal value of vbMonday which is 2.
The for the Date, You will need to use Date().

StartDate: DateAdd("d", 2 - DatePart("w", Date()) -7, Date())
EndDate: DateAdd("d",Weekday(Date(), 1, [StartDate])

Another way to do this is to create hidden controls on your form that have
the expressions as their control source. then your criteria for StartTime
would be
BETWEEN "#" & Forms!MyFormName!StartDateControlName & "#" AND "#" &
Forms!MyFormName!EndDateControlName & "#"

Pam said:
I'm sorry, but I'm not doing something right. Okay, I have my query open
in
design view. I go to next blank column and click Expression Builder
icon.
The box opens and I type in your function StartDate:
DateAdd("d",vbMonday - DatePart("w", Date) -7, Date) and then do the
same
for EndDate. Next, I go to MY date field, which is titled StartTime
(date
and time field) and enter the criteria BETWEEN [StartDate] AND
[EndDate].

Doing it this way, I'm prompted for vbMonday and Date parameter values.
When I enter thru those, I get "too complex" message.
If you would be so kind as to tell me what I'm doing wrong, I would
appreciate it.
Thanks,
Pam




Klatuu said:
The function I sent to find the Monday should replace your query which
is
returning Sunday instead of Monday, however, neither of the expressions
should be in the critera part of your query (assuming you are using the
query
builder). The way to do this is to create two calculated fieds in your
query
StartDate and EndDate
The Start Date field would have the name followed by " and then the
expression:

StartDate: DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

The End date woud be:

EndDate: DateAdd("d",Weekday(Date,vbMonday)-1, [StartDate])

The the Criteria field on your date field would be
BETWEEN [StartDate] AND [EndDate]

As to the error you got, be sure you copied the code correctly, I
tested
these expressions in the immediate pane, so there should not be a
syntax
problem.


:

Klatuu,
Thank you for answering. The expression I listed in my first message
is
in
my query under StartTime criteria. Do I put the function you gave in
the
same place? And do I combine them with "Between...And..."? If so, I
tried
that and it returns an error message of "The expression you entered
has
an
invalid (dot) or ! operator or invalid parentheses" and the curser
flashes
on the parenthesis before the "w".
Thanks again,
Pam


This function:
DateAdd("d",-6-Weekday(Date()),Date())
Actually returns a Sunday date, not a Monday.
This function will return the Monday date for the previous week:

dtmFromDate = DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

Then to get the To Date that will be the same day of the week one
week
prior
to today:

dmToDate = DateAdd("d",Weekday(Date,vbMonday)-1, dtmFromDate)

:

Hi,
I have a report that returns a list of work done weekly. The
expression
I
am using now is only good for looking at the report on Monday (7
days
prior). Work week is Monday thru Sunday. Is there a calculation
that
will
give me the work completed and totaled from Monday to any day of
that
week.
Say if report was reviewed on Tuesday and then on Thursday, it
would
give
totals from Monday thru Tuesday and then again from Monday thru
Thursday.
Here is what I am using now:

Between DateAdd("d",-6-Weekday(Date()),Date()) And
DateAdd("d",1-Weekday(Date()),Date())

Any help is greatly appreciated!
Thanks,
Pam
 
K

Klatuu

It got a little mixed up with all the changes. Try this:

EndDate: DateAdd("d",Weekday(Date(), 2) -1, [StartDate])

Pam said:
Okay, I entered the two function lines you listed below and put each in a
column on the query. EndDate gives error msg "The expression you entered
has a function containing the wrong number of arguments." I find the date
functions to be the most difficult to decipher, so I'm not sure what to do
with it.


Klatuu said:
Doh!
Sorry, Jet doesn't understand Access constants. My bad.
You will need to use the literal value of vbMonday which is 2.
The for the Date, You will need to use Date().

StartDate: DateAdd("d", 2 - DatePart("w", Date()) -7, Date())
EndDate: DateAdd("d",Weekday(Date(), 1, [StartDate])

Another way to do this is to create hidden controls on your form that have
the expressions as their control source. then your criteria for StartTime
would be
BETWEEN "#" & Forms!MyFormName!StartDateControlName & "#" AND "#" &
Forms!MyFormName!EndDateControlName & "#"

Pam said:
I'm sorry, but I'm not doing something right. Okay, I have my query open
in
design view. I go to next blank column and click Expression Builder
icon.
The box opens and I type in your function StartDate:
DateAdd("d",vbMonday - DatePart("w", Date) -7, Date) and then do the
same
for EndDate. Next, I go to MY date field, which is titled StartTime
(date
and time field) and enter the criteria BETWEEN [StartDate] AND
[EndDate].

Doing it this way, I'm prompted for vbMonday and Date parameter values.
When I enter thru those, I get "too complex" message.
If you would be so kind as to tell me what I'm doing wrong, I would
appreciate it.
Thanks,
Pam




The function I sent to find the Monday should replace your query which
is
returning Sunday instead of Monday, however, neither of the expressions
should be in the critera part of your query (assuming you are using the
query
builder). The way to do this is to create two calculated fieds in your
query
StartDate and EndDate
The Start Date field would have the name followed by " and then the
expression:

StartDate: DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

The End date woud be:

EndDate: DateAdd("d",Weekday(Date,vbMonday)-1, [StartDate])

The the Criteria field on your date field would be
BETWEEN [StartDate] AND [EndDate]

As to the error you got, be sure you copied the code correctly, I
tested
these expressions in the immediate pane, so there should not be a
syntax
problem.


:

Klatuu,
Thank you for answering. The expression I listed in my first message
is
in
my query under StartTime criteria. Do I put the function you gave in
the
same place? And do I combine them with "Between...And..."? If so, I
tried
that and it returns an error message of "The expression you entered
has
an
invalid (dot) or ! operator or invalid parentheses" and the curser
flashes
on the parenthesis before the "w".
Thanks again,
Pam


This function:
DateAdd("d",-6-Weekday(Date()),Date())
Actually returns a Sunday date, not a Monday.
This function will return the Monday date for the previous week:

dtmFromDate = DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

Then to get the To Date that will be the same day of the week one
week
prior
to today:

dmToDate = DateAdd("d",Weekday(Date,vbMonday)-1, dtmFromDate)

:

Hi,
I have a report that returns a list of work done weekly. The
expression
I
am using now is only good for looking at the report on Monday (7
days
prior). Work week is Monday thru Sunday. Is there a calculation
that
will
give me the work completed and totaled from Monday to any day of
that
week.
Say if report was reviewed on Tuesday and then on Thursday, it
would
give
totals from Monday thru Tuesday and then again from Monday thru
Thursday.
Here is what I am using now:

Between DateAdd("d",-6-Weekday(Date()),Date()) And
DateAdd("d",1-Weekday(Date()),Date())

Any help is greatly appreciated!
Thanks,
Pam
 
K

Klatuu

It got a little mixed up with all the changes. Try this:

EndDate: DateAdd("d",Weekday(Date(), 2) -1, [StartDate])

Pam said:
Okay, I entered the two function lines you listed below and put each in a
column on the query. EndDate gives error msg "The expression you entered
has a function containing the wrong number of arguments." I find the date
functions to be the most difficult to decipher, so I'm not sure what to do
with it.


Klatuu said:
Doh!
Sorry, Jet doesn't understand Access constants. My bad.
You will need to use the literal value of vbMonday which is 2.
The for the Date, You will need to use Date().

StartDate: DateAdd("d", 2 - DatePart("w", Date()) -7, Date())
EndDate: DateAdd("d",Weekday(Date(), 1, [StartDate])

Another way to do this is to create hidden controls on your form that have
the expressions as their control source. then your criteria for StartTime
would be
BETWEEN "#" & Forms!MyFormName!StartDateControlName & "#" AND "#" &
Forms!MyFormName!EndDateControlName & "#"

Pam said:
I'm sorry, but I'm not doing something right. Okay, I have my query open
in
design view. I go to next blank column and click Expression Builder
icon.
The box opens and I type in your function StartDate:
DateAdd("d",vbMonday - DatePart("w", Date) -7, Date) and then do the
same
for EndDate. Next, I go to MY date field, which is titled StartTime
(date
and time field) and enter the criteria BETWEEN [StartDate] AND
[EndDate].

Doing it this way, I'm prompted for vbMonday and Date parameter values.
When I enter thru those, I get "too complex" message.
If you would be so kind as to tell me what I'm doing wrong, I would
appreciate it.
Thanks,
Pam




The function I sent to find the Monday should replace your query which
is
returning Sunday instead of Monday, however, neither of the expressions
should be in the critera part of your query (assuming you are using the
query
builder). The way to do this is to create two calculated fieds in your
query
StartDate and EndDate
The Start Date field would have the name followed by " and then the
expression:

StartDate: DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

The End date woud be:

EndDate: DateAdd("d",Weekday(Date,vbMonday)-1, [StartDate])

The the Criteria field on your date field would be
BETWEEN [StartDate] AND [EndDate]

As to the error you got, be sure you copied the code correctly, I
tested
these expressions in the immediate pane, so there should not be a
syntax
problem.


:

Klatuu,
Thank you for answering. The expression I listed in my first message
is
in
my query under StartTime criteria. Do I put the function you gave in
the
same place? And do I combine them with "Between...And..."? If so, I
tried
that and it returns an error message of "The expression you entered
has
an
invalid (dot) or ! operator or invalid parentheses" and the curser
flashes
on the parenthesis before the "w".
Thanks again,
Pam


This function:
DateAdd("d",-6-Weekday(Date()),Date())
Actually returns a Sunday date, not a Monday.
This function will return the Monday date for the previous week:

dtmFromDate = DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

Then to get the To Date that will be the same day of the week one
week
prior
to today:

dmToDate = DateAdd("d",Weekday(Date,vbMonday)-1, dtmFromDate)

:

Hi,
I have a report that returns a list of work done weekly. The
expression
I
am using now is only good for looking at the report on Monday (7
days
prior). Work week is Monday thru Sunday. Is there a calculation
that
will
give me the work completed and totaled from Monday to any day of
that
week.
Say if report was reviewed on Tuesday and then on Thursday, it
would
give
totals from Monday thru Tuesday and then again from Monday thru
Thursday.
Here is what I am using now:

Between DateAdd("d",-6-Weekday(Date()),Date()) And
DateAdd("d",1-Weekday(Date()),Date())

Any help is greatly appreciated!
Thanks,
Pam
 
P

Pam

Well I tried it both ways and it asks for StartDate and EndDate parameters.
It also gives a "too complex message". I give up. They will just have to
look at the report on Mondays only. Thanks again for your time and help.
Much appreciated!!
Pam
Klatuu said:
It got a little mixed up with all the changes. Try this:

EndDate: DateAdd("d",Weekday(Date(), 2) -1, [StartDate])

Pam said:
Okay, I entered the two function lines you listed below and put each in a
column on the query. EndDate gives error msg "The expression you entered
has a function containing the wrong number of arguments." I find the
date
functions to be the most difficult to decipher, so I'm not sure what to
do
with it.


Klatuu said:
Doh!
Sorry, Jet doesn't understand Access constants. My bad.
You will need to use the literal value of vbMonday which is 2.
The for the Date, You will need to use Date().

StartDate: DateAdd("d", 2 - DatePart("w", Date()) -7, Date())
EndDate: DateAdd("d",Weekday(Date(), 1, [StartDate])

Another way to do this is to create hidden controls on your form that
have
the expressions as their control source. then your criteria for
StartTime
would be
BETWEEN "#" & Forms!MyFormName!StartDateControlName & "#" AND "#" &
Forms!MyFormName!EndDateControlName & "#"

:

I'm sorry, but I'm not doing something right. Okay, I have my query
open
in
design view. I go to next blank column and click Expression Builder
icon.
The box opens and I type in your function StartDate:
DateAdd("d",vbMonday - DatePart("w", Date) -7, Date) and then do
the
same
for EndDate. Next, I go to MY date field, which is titled StartTime
(date
and time field) and enter the criteria BETWEEN [StartDate] AND
[EndDate].

Doing it this way, I'm prompted for vbMonday and Date parameter
values.
When I enter thru those, I get "too complex" message.
If you would be so kind as to tell me what I'm doing wrong, I would
appreciate it.
Thanks,
Pam




The function I sent to find the Monday should replace your query
which
is
returning Sunday instead of Monday, however, neither of the
expressions
should be in the critera part of your query (assuming you are using
the
query
builder). The way to do this is to create two calculated fieds in
your
query
StartDate and EndDate
The Start Date field would have the name followed by " and then the
expression:

StartDate: DateAdd("d",vbMonday - DatePart("w", Date) -7, Date)

The End date woud be:

EndDate: DateAdd("d",Weekday(Date,vbMonday)-1, [StartDate])

The the Criteria field on your date field would be
BETWEEN [StartDate] AND [EndDate]

As to the error you got, be sure you copied the code correctly, I
tested
these expressions in the immediate pane, so there should not be a
syntax
problem.


:

Klatuu,
Thank you for answering. The expression I listed in my first
message
is
in
my query under StartTime criteria. Do I put the function you gave
in
the
same place? And do I combine them with "Between...And..."? If so,
I
tried
that and it returns an error message of "The expression you entered
has
an
invalid (dot) or ! operator or invalid parentheses" and the curser
flashes
on the parenthesis before the "w".
Thanks again,
Pam


This function:
DateAdd("d",-6-Weekday(Date()),Date())
Actually returns a Sunday date, not a Monday.
This function will return the Monday date for the previous week:

dtmFromDate = DateAdd("d",vbMonday - DatePart("w", Date) -7,
Date)

Then to get the To Date that will be the same day of the week one
week
prior
to today:

dmToDate = DateAdd("d",Weekday(Date,vbMonday)-1, dtmFromDate)

:

Hi,
I have a report that returns a list of work done weekly. The
expression
I
am using now is only good for looking at the report on Monday (7
days
prior). Work week is Monday thru Sunday. Is there a
calculation
that
will
give me the work completed and totaled from Monday to any day of
that
week.
Say if report was reviewed on Tuesday and then on Thursday, it
would
give
totals from Monday thru Tuesday and then again from Monday thru
Thursday.
Here is what I am using now:

Between DateAdd("d",-6-Weekday(Date()),Date()) And
DateAdd("d",1-Weekday(Date()),Date())

Any help is greatly appreciated!
Thanks,
Pam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top