date has me stumped

# Thread: date has me stumped

1. Senior Member
Join Date
Dec 1969
Posts
336

## date has me stumped

I am trying to pass a week number of a month. If I pass week 2 of March to my asp page, I need it to figure out the first day of the week for that week. So essentially, I need it to take the week number of 2 and figure out that the first date that week is the 4th. Anyone have an idea on how to do this?

2. J Guest

## RE: date has me stumped

try this...<BR><BR>dim dayofweek, daydiff, firstdateofweek, testdate<BR>testdate = #3/25/2001#<BR>dayofweek = DatePart("w", testdate, 1)<BR>daydiff = GetDayDifference(dayofweek)<BR><BR>firstdateofweek = DateAdd("d", daydiff, testdate)<BR>Response.Write(firstdateofweek & "<BR>")<BR><BR>Function GetDayDifference(CurrentDayOfWeek)<BR> Dim FirstDayOfWeek <BR> FirstDayOfWeek = 1<BR> GetDayDifference = -1*(CurrentDayOfWeek - FirstDayOfWeek)<BR>End Function<BR><BR>This will grab the date of Sunday in any given week. You can tweek it to return whatever day you want. Cheers.

3. Senior Member
Join Date
Dec 1969
Posts
336

## why do the multiplication

I&#039;m trying to figure out your logic here and I&#039;m having a tough time figuring out the need for the multiplication portion of the function. Can you give me a little insight to your thinking process when you came up with this? By the way, it&#039;s just what I was looking for and it works great! Thanks a lot.

4. Senior Member
Join Date
Dec 1969
Posts
336

## nevermind, I think I figured it out, but....

How do you go about thinking up these kind of formulas? I have such a hard time thinking through something like this. Any pointers would be greatly appreciated. Thanks.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•