ASP: Mini Month Calendar


Introduction

Author: Martin Warning
Year: 2007
License: Free

This example creates a mini calendar for a given month. You could use this example for a calendar navigation by making each day a link to that day's page or use it on a blog/news site to allow navigation to items from a given day.

This example will display the calendar for the month/year indicated in the intMiniCalMonth and intMiniCalYear variables. The example uses the current month and year. This code requires the fncLastDay function.

Code

Languages: The following code is an example display of a months calendar:
<%
	Dim intMiniCalMonth : intMiniCalMonth = Month(Date())
	Dim intMiniCalYear : intMiniCalYear = Year(Date())
%>
<div align="center"><b><%=MonthName(intMiniCalMonth) & " " & intMiniCalYear%></b>
	<table cellspacing="2">
	<colgroup span="7" width="30" align="center">
	</colgroup>
	<tr>
		<th title="Monday" style="background-color:#055005;color:#fff;font-weight:bold;">M</th>
		<th title="Tuesday" style="background-color:#055005;color:#fff;font-weight:bold;">T</th>
		<th title="Wednesday" style="background-color:#055005;color:#fff;font-weight:bold;">W</th>
		<th title="Thursday" style="background-color:#055005;color:#fff;font-weight:bold;">T</th>
		<th title="Friday" style="background-color:#055005;color:#fff;font-weight:bold;">F</th>
		<th title="Saturday" style="background-color:#055005;color:#fff;font-weight:bold;">S</th>
		<th title="Sunday" style="background-color:#055005;color:#fff;font-weight:bold;">S</th>
	</tr>
	<tr>
	<%
	' First row
	Dim intFirstDay, intFirstRowDay, intLastDay, intLastRowDay, i
	Dim intDayColumn : intDayColumn = 1

	If Weekday(intMiniCalMonth & "/1/" & intMiniCalYear) = 1 Then
		intFirstDay = 6
	Else
		intFirstDay = Weekday(intMiniCalMonth & "/1/" & intMiniCalYear) - 2
	End If

	For i = 1 TO intFirstDay
		Response.Write("<td> </td>")
	Next
	For i = 1 TO 7 - intFirstDay
		Response.Write("<td style=""background-color:#eee;"" align=""center"">" & i & "</td>")
		intFirstRowDay = i
	Next

	' Subsequent rows
	For i = intFirstRowDay + 1 TO fncLastDay(intMiniCalMonth,intMiniCalYear)
		If intDayColumn = 1 Then
			Response.Write("</tr><tr>")
		End If

		Response.Write("<td style=""background-color:#eee;"" align=""center"">" & i & "</td>")

		If intDayColumn <> 7 Then
			intDayColumn = intDayColumn + 1
		Else
			intDayColumn = 1
		End If
	Next

	' Finish the last row
	If Weekday(intMiniCalMonth & "/" & fncLastDay(intMiniCalMonth,intMiniCalYear) & "/" & intMiniCalYear) = 1 Then
		intLastDay = 0
	Else
		intLastDay = 8 - Weekday(intMiniCalMonth & "/" & fncLastDay(intMiniCalMonth,intMiniCalYear) & "/" & intMiniCalYear)
	End If

	For i = 1 TO intLastDay
		Response.Write("<td>&nbsp;</td>")
	Next
	%>
	</tr>
	</table>
</div>

Example: See it in action

Downloads

ASP:
Zip file example1.zip


Printed from: http://flyinglowlander.com/ (5/20/2012)
© FlyingLowander.com 2006 - 2012

Visit http://flyinglowlander.com for more XHTML, CSS, ASP and JavaScript examples, templates and tutorials.