|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Simple, Easy and Modifiable Monthly Calendar
This is a simple monthly calendar that allows you to select the month and year
then generates the calendar for the year. Because of the way it works and with only
a minimal amount of calculations, it makes it very easy to modify or manipulate.
Since the calendar is rendered from a starting date to an ending date,
that also simplifies being able to run a query on dates against a database
to check for events or schedules.
Here is the ASP code for this script:
<%
TheMonth = Request("TheMonth")
If Len(Trim(TheMonth)) = 0 Then
TheMonth = Month(Date())
End If
TheMonth = Cint(TheMonth)
TheYear = Request("TheYear")
If Len(Trim(TheYear)) <> 4 OR IsNumeric(TheYear) = False Then
TheYear = Year(Date())
End If
TheMonths = ",January,Febuary,March,April,May,June" & _
",July,August,September,October,Novemeber,December"
MonthArr = Split(TheMonths,",")
TheDays = ",Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
DaysArr = Split(TheDays,",")
NumDays = 0
If TheMonth = 2 Then
NumDays = 28
If TheYear Mod 4 = 0 Then
NumDays = 29
End If
ElseIf TheMonth <= 7 Then
If TheMonth Mod 2 = 1 Then
NumDays = 31
Else
NumDays = 30
End If
Else
If TheMonth Mod 2 = 0 Then
NumDays = 31
Else
NumDays = 30
End If
End If
FirstOfMonth = CDate(TheMonth & "/01/" & TheYear)
FirstDay = Weekday(FirstOfMonth)
FirstDayName = WeekdayName(FirstDay)
EndOfMonth = CDate(TheMonth & "/" & NumDays & "/" & TheYear)
LastDay = Weekday(EndOfMonth)
StartDate = FirstOfMonth - (FirstDay-1)
EndDate = EndOfMonth + (7-LastDay)
%>
<form name="SelMonthYear" method="post" action="Calendar.asp">
<table class="DataTble" cellspacing="0" align="center">
<tr class="bnotes" style="font-weight:bold;">
<td>
Month
<select name="TheMonth" class="bnotes">
<%
For x = 1 to UBound(MonthArr)
If TheMonth = x Then
Response.Write "<option value=" & chr(34) & x & chr(34) & " selected>" & _
MonthArr(x) & _
"</option>" & chr(13)
Else
Response.Write "<option value=" & chr(34) & x & chr(34) & ">" & _
MonthArr(x) & _
"</option>" & chr(13)
End If
Next
%>
</select>
</td>
<td>
Year
<input type="text" name="TheYear" class="bnotes" size="3" value="<%=TheYear%>">
</td>
<td>
<input type="submit" value="Go" class="SubButton">
</td>
</tr>
</table>
</form>
<table class="DataTble" cellspacing="0" align="center">
<tr>
<td class="CalMonth" style="text-align:center;font-size:12pt;" colspan="7">
<%=MonthArr(TheMonth)%> <%=TheYear%>
</td>
</tr>
<tr>
<%
For x = 1 To UBound(DaysArr)
Response.Write "<td class=" & chr(34) & "CalDayName" & chr(34) & ">" & _
DaysArr(x) & _
"</td>" & chr(13)
Next
For x = StartDate to EndDate
If x Mod 7 = 1 Then
Response.Write "<tr class=" & chr(34) & "bnotes" & chr(34) & ">"
End If
If x = Date() Then
TheCellStyle = "IsToday"
ElseIf x < FirstOfMonth OR x > EndOfMonth Then
TheCellStyle = "NotMonthDay"
Else
TheCellStyle = "IsMonthDay"
End If
Response.Write "<td class=" & chr(34) & TheCellStyle & chr(34) & ">" & _
"<b>" & Day(x) & "</b><br>" & _
"</td>"
If x Mod 7 = 0 Then
Response.Write "</tr>"
End If
Next
%>
</tr>
</table>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||