Date Field to be the next given Monday

RussPhi

New member
Local time
Today, 04:47
Joined
Jan 3, 2020
Messages
12
Hi
I have a date field called (EndDate) that i can pick on the date picker "cumbersome" what I want to do on a "dble click" is to change the date to the monday of next week. So if today is Monday the 28th of Nov I want the date field to show next Monday the 5th of Dec. and if today is Nov 29th Tuesday I want it to show Monday the 5th of Dec. so no matter what the current day is this week I want the next week Monday. hope this makes sense.

Much tanks for any help.
 
The attached file has a number of Useful Date Functions. I'm sure it will have something of use to you.
I take NO CREDIT for its conception. Our thanks go to Pat Hartman for its existence.
 

Attachments

Here's what I use:
Code:
DateAdd("d", 8-Weekday(Date(),2), Date())
Hope that helps...
 
I think the function you will need is:
Code:
Function fDateDayAfter(dtmDate As Date, bytDaySought As Byte) As Date
'   Function to return the date of the named day after the passed date
'   Accepts:dtmDate - any date
'   bytDaySought (e.g. vbMonday)
    If bytDaySought - WeekDay(dtmDate) >= 0 Then
        fDateDayAfter = dtmDate + bytDaySought - WeekDay(dtmDate)
    Else
        fDateDayAfter = dtmDate + bytDaySought - WeekDay(dtmDate) + 7
    End If
End Function
which can be found in the code module of the form called sfrmFirstWeekday
 
1669740059996.png
this is what I'm geting what am i doing wrong.
 
Try:
Me.EndDate = DateAdd("d", 8-Weekday(Date(),2), Date())
 
Here's a link to the most recent version. You have a very old version. Ten years:) This was one of the first samples I ever made. I also added a change log to the newest version so you can see some of the changes I made in the past couple of years. If you have copies of my other sample db's you might want to see if there is a newer version in the sample-date-functions. I've updated almost all of the samples within the past two years:) Here's all the links
:eek: 10 years. Where did they go? I hadn't realized I'd been a fan for so long. I've used several of your functions over the years and offered them to many posters here and on other forums. Thanks for the link Pat.
 
I thank all of you for your wounder work and minds of knowledge as well.
 
I must say that when I have needed to do something like that, I tend not to try to find an elegant one-line solution and use something I can actually follow!

I would do more

Code:
nextdate=nextdate+1 'in case today actually is a monday
while day(nextdate)<>vbmonday
    nextdate=nextdate+1   
wend
 

Users who are viewing this thread

Back
Top Bottom