Working with Days of the week

G

Guest

Hi

I'm trying to build up my own code and I need to be able to identify last
Wednesday, next Tuesday, that sort of thing. I believe the following
identifies last Wednesday, but I don't really understand how it works:

DateAdd("d", 1 - Weekday(Date, vbWednesday), Date)

If this is correct, what would the code be to identify last Thursday, or
last Friday?Also, what would be code be to identify next Wednesday, next
Thursday, next Friday etc? If I could see these, I could figure out what the
various parts of the code are actually doing. Unless someone could do that
easily or point me towards some good links for this type of thing.

Many thanks for the help. JohnB
 
G

Guest

so if its tuesday your code says
go by days "d"
subtract 6 days from Date()
first day is wednesday
And today is tuesday
Wed=1
then tuesday=7
1-7=-6

Jon Bricker
 
G

Guest

Swithing the '1-' on the other side will give you next Wednesday. change the
day for different days.
 
G

Guest

Thanks for this and sorry for the delay in getting back to you.

I'm also sorry to say I'm baffled by your reply. Are you describing what my
sample code is doing, in which case where does -6 figure? What does the 1- do
in the code? Perhaps if you took my code and modified it to select , say,
last Thursday and then in a second sample have it select, say, next Thursday,
I could perhaps understand your reply a bit better.

Thanks for the help, JohnB
 
G

Guest

I'm trying to build up my own code and I need to be able to identify last
Wednesday, next Tuesday, that sort of thing. I believe the following
identifies last Wednesday, but I don't really understand how it works:

DateAdd("d", 1 - Weekday(Date, vbWednesday), Date)
''''''''''''''''''''''
weekday works that you start on a day specificed in this case its wednesday
and go to the date specified. weekday(date,vbwednesday) the result if its
tuesday is 7 or the last day in your week first day being wednesday.

So that result = 1-7 which figures a negative 6 in your datadd(,-6,)
your dateadd says go by days "d" subtract 6 from Date() or
dateadd("d",-6,date())

if you want last Thursday you would enter vbthursday instead of vbwednesday.

if you want next Wednesday you would write your statement as
dateadd("d",weekday(date(),vbwednesday) -1,date()) so your dateadd will be
("d",6,date()) instead of a -6.
 
G

Guest

Thank you. I think I get it now - I appreciate your taking the time to
explain.

One more question, if I you would allow me. I understand that the code
sample I quoted selects midnight last Wednesday. If I wanted it to select
another time, say 12.00 (mid day) last Wednesday, how would the code line
look? I promise this will be the last question in this thread.

Thanks again, JohnB
 

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

Similar Threads


Top