DateFunction - first/last day of week

Thread: DateFunction - first/last day of week

1. Senior Member
Join Date
Dec 1969
Posts
330

DateFunction - first/last day of week

Hello all - I&#039;m hoping someone can help me with a date function problem I&#039;m having. Basically I looking to be able to get the first date and last date of a given week of any given month. So say I&#039;ve got the Month of May and my calendar runs Sunday through Saturday. I would like to know what the date is on Sunday and Saturday for each week. So for instance for this week it would return the 6th and the 12th. Can someone help? Thanks.

2. Eddie Campbell Guest

RE: DateFunction - first/last day of week

This works:<BR><BR>MyDate = "8-May-01" &#039; Make this any date you like<BR><BR>Sunday = DateAdd("d", 1-DatePart("w",MyDate,1), MyDate)<BR>Saturday = DateAdd("d", 6, Sunday)<BR>Response.Write "The week runs from " & Sunday & " to " & Saturday

3. Senior Member
Join Date
Dec 1969
Posts
330

RE: DateFunction - first/last day of week

Thanks for the response Eddie. Let me ask another question - I&#039;m really not a slacker - I just cannot figure out how to get this to work. What I&#039;m doing is building an event calendar. It loops through building a table with one row for each week. What I would like to do is to have a button/link at the beginning of each week row that would take them to a page to see all the events for that given week. So link would be something like:<BR><BR>&#060;a href=events_week.asp?first=5/6/2001&last=5/12/2001<BR><BR>I&#039;m not sure how I would get this to work in my loop using the &#039;myDate&#039; portion. Would there be an easier way to do this? Or do you think your way would work in my loop somehow?<BR><BR>Thanks again for the help - I&#039;m going nuts here!

4. Eddie Campbell Guest

RE: DateFunction - first/last day of week

Well, you could put my code into a function and call it from within your loop<BR><BR>Function BuildLink(MyDate)<BR>Sunday = DateAdd("d", 1-DatePart("w",MyDate,1), MyDate) <BR>Saturday = DateAdd("d", 6, Sunday) <BR>Response.Write "&#060;a href=""events_week.asp?first=" & Sunday & "&last=" & Saturday & """&#062;Click to see events&#060;/a&#062;"<BR>End Function<BR><BR>So in your loop when you want to display the link, you do this<BR><BR>&#060;% =BuildLink "08-May-01" %&#062; <BR><BR>I haven&#039;t tested this, but it should work

5. Senior Member
Join Date
Dec 1969
Posts
330

Thanks Eddie - I think I can make this work <

.

Posting Permissions

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