Marcus
Marcus

Reputation: 9439

Get the Monday of this week where a week is Mon - Sun (VBScript)

In VBScript, how can I get the Monday of the current week, assuming a week is Mon-Sun and not Sun-Sat?

The following code returns the Monday when a week is Sun-Sat, so it's close but not quite right:

Private Function getMonday(d)
    getMonday = DATEADD("d", 2 - WEEKDAY(d), d)
End Function

How can I do this without changing any LCID settings?

Upvotes: 1

Views: 1803

Answers (1)

nickles80
nickles80

Reputation: 1101

Weekday takes a second argument to specify the first day of the week.

http://msdn.microsoft.com/en-us/library/t51x9wtx(v=vs.84).aspx

So DateAdd("d", 1 - WeekDay(d, 2), d)

I didn't test this to make sure my logic is correct. But the technique should work for you.

Upvotes: 4

Related Questions