Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find This Weeks Monday

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

like image 248
neojakey Avatar asked Jan 16 '12 17:01

neojakey


People also ask

Is there a This week function in Excel?

The WEEKNUM Function[1] is an Excel DATE and TIME Function. It will return the week number of a specific date. The function will return an integer that represents a week number from 1 to 52 weeks of the year. WEEKNUM is quite useful in financial analysis.

How do I get the Monday of the week number in Excel?

As you see, our formula consists of 2 parts: DATE(A2, 1, -2) - WEEKDAY(DATE(A2, 1, 3)) - calculates the date of the last Monday in the previous year. B2 * 7 - adds the number of weeks multiplied by 7 (the number of days in a week) to get the Monday (start date) of the week in question.


2 Answers

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)
like image 135
drf Avatar answered Sep 24 '22 01:09

drf


VBScript has a function called WeekDay, it return 1 - 7, not sure whether 1 is Monday though, usually you can twiddle with that.

Either way get the weekday Thursday = 4? , so then you just need to take three days off your date with thae DateAdd function

like image 23
Tony Hopkinson Avatar answered Sep 27 '22 01:09

Tony Hopkinson