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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Calendar Script

Status
Not open for further replies.

waiting12345

Technical User
Dec 9, 2005
9
GB
Hi, I'm trying to create a simple calendar script, what I want to be able to do is loop through all the weeks as the rows and then the days in the week as columns. My problem lies in that the counter starts at 1 which means the first day appears always on monday which is not the case. I'd appreciate if someone could help adjust this to work properly. One final thing to mention is that it's pretty imperitive that I don't have a seperate loop for the first week as i'm eventually going to add some pretty hefty work inside the table and don't want to load it twice. Cheers

Code:
<%
' loop for the remaining weeks in the month
vblvntDayCounter = 0
for vblvntWeeks = 1 to 5 %>
	<tr>
		<%
		' loop for the remaing days of the month
		for vblvntCounter = 1 to 7
			vblvntDayCounter = vblvntDayCounter + 1
			' write out the date and place in bold if it's the current date
			if vblvntDayCounter <= vblvntLastDay then %>
				<td align="center"><%=vblvntDayCounter%></td>
			<% end if
		next %>
	</tr>
<% next %>
 
Not sure exactly what you want but this approach might work.

Determine the date you want to start the calendar with.
Determine what day of the week that date represents and if needed subtract from the date so that you end up with the first day of the week that date resides in.
Then you build your calendar sequentially from that point.

For instance, if your date is 12/22/2005 then the day of the week would be Thursday which is represented as day 5.
So you would subtract 4 days from your date to end up with the date for Sunday the 18th. Then loop forward from that date.

I would examine each date to see when the month changes so you can alter background color of the cell, and if it is the current date to alter the color of the day.


Paranoid? ME?? WHO WANTS TO KNOW????
 
This determines the day of the week indicated by startdate and subtracts the number of days past Sunday giving you the date corresponding to the first day of that week.

Code:
startdate = "11/24/2005"
weekstartdate = DATEADD("d",-(weekday(startdate)-1),startdate)


Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top