Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<b>Calendar Weekly View</b>

Status
Not open for further replies.

secondreckoned

Technical User
Jan 20, 2004
35
CA
<b>Hi I believe I am a little out of my league here, and need a bit of help with logic. I can produce a calendar with a monthly view; however, I want to build a caledar that shows a year in 7 day periods ie;
2007
Sunday Monday Tuesday Wednesday
Jan 07 Jan 08 Jan 09 Jan 10
Thursday Friday Saturday
Jan 11 Jan 12 Jan 13

Sunday Monday Tuesday Wednesday
Jan 14 Jan 15 Jan 16 Jan 17
Thursday Friday Saturday
Jan 18 Jan 19 Jan 20

etc., etc.

I hope this makes sense...I'm kind of stuck as to where to begin. Has anyone done something like this before? If so can you give me some pointers? Thank you in advance
</b>
 
Are you trying to show the whole year on one page, or do you want to basically show one week at a time and allow the user to page back and forth through the weeks? Or...?


It's fairly easy to output a week, given a start date. Something like:
Code:
Dim startDate, dayCtr, tempDate
startDate = #12/3/2006#

'start output
Response.Write "<table>"

'loop through 7 days
For dayCtr = 0 to 6
   'set the date we're working with
   tempDate = DateAdd("d",dayCtr,startDate)

   'if it is sunday or thursday, start a new row
   If WeekDay(tempDate) = 1 Or WeekDay(tempDate) = 5 Then
      response.Write "<tr>"
   End If

   'output the weekday and short date
   Response.Write "<td><div class=""weekday"">" & WeekDayName(WeekDay(tempDate)) & "</div>"
   Response.Write "<div class=""shortdate"">" & Left(MonthName(Month(tempDate)),3) & " " & Day(tempDate) & "</div></td>"

   'If it is Wednesday or Saturday, end the row
   If WeekDay(tempDate) = 4 Or WeekDay(tempDate) = 7 Then
      Response.Write "</tr>"
   End If
Next
Response.Write "</table>"

As you can see, we can easily output a single week in the format you posted above by looping through a 7 day period and using some f the built-in date functions to create the same output. It wouldn't be too hard to create a next and back link also.

Now if you do want to display all the weeks of a year, one after another, in the page, then your going to have alot of content. You could easily put the table and loop above into a function and create a loop that calls that function with a new start date inside a loop. Basically something like:
Code:
'assuming the function is named OutputWeek and accepts a StartDate as it's only argument
Dim dateCtr

'find the first Sunday preceding the new year
dateCtr = #1/1/2006#
dateCtr = DateAdd("d",-1 * WeekDay(dateCtr) + 1,dateCtr)

'loop to output each week until we exceed dec 31
Do Until dateCtr > '12/31/2006'
   OuputWeek dateCtr
   dateCtr = dateAdd("d",7,dateCtr)
Loop


Hope this helps some. If I was too far off, try providing a little more information on what you have tried so far and the goal of what your doing, and we may be able to help with a better fitting solution or path to a solution.

-T

 
Thanks for your help, it helped lead me to my solution...

Function ShowWeek(dDate)
Dim k 'number value for day of the week.
Dim i 'counter.
Dim dTemp 'temporary holder for calendar disply data.

k = Weekday(dDate, 1)
i = 1
Do Until i = 8
If i = k Then
dTemp = dTemp & "<tr><td bgcolor=#a0a0a0 width=60 align=center><font color=#000099>" & DateAdd("w", i-k, dDate) & "</font></td><td bgcolor=#a0a0a0 width=640><b><a href=weekly.asp?date=" & DateAdd("w", i-k, dDate) & ">" & WeekDayName(Weekday(DateAdd("w", i-k, dDate), 1)) & "</a></b></td></tr>"
Else
dTemp = dTemp & "<tr><td bgcolor=#c0c0c0 width=60 align=center>" & DateAdd("w", i-k, dDate) & "</td><td bgcolor=#c0c0c0 width=640><b><a href=weekly.asp?date=" & DateAdd("w", i-k, dDate) & ">" & WeekDayName(Weekday(DateAdd("w", i-k, dDate), 1)) & "</a></b></td></tr>"
End If
i = i + 1
Loop
ShowWeek = dTemp
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top