Find This Weeks Monday

asp-classicvbscript

How do I get the date of this current week's Monday. Where Monday is the first day of the week. So if I was to look up this weeks it would return the date 1/16/2012

I am using VBScript and ASP

Many thanks in advance..

Paul

Best Answer

Effectively, the Weekday function returns Sunday=1, Monday=2, etc. To get the Monday of the same week, you want to subtract:

Sunday (1): 6 days
Monday (2): 0 days
Tuesday(3): 1 day
...
Saturday(7): 5 days.

Or Days to subtract = (Weekday - 2 + 7) Mod 7

So if d is a date, the Monday of the same week can be written as:

mondayofsameweek = DateAdd("d", -((Weekday(d) + 7 - 2) Mod 7), d)
Related Topic