dbWriter ASP calendar code
A calendar that returns the last day
of the month and takes into account leap years!!
You have selected -- 9/8/2008
<%
Dim iMonth 'Month of calendar
Dim iYear 'Year of calendar
Dim FirstDay 'First day of the month. 0 = Sunday
Dim CurrentDay 'Used to print dates in calendar
Dim Col 'Calendar column
Dim Row 'Calendar row
iMonth = cint(Request.Querystring("Month"))
iYear = cint(Request.Querystring("Year"))
If iMonth = 0 then iMonth = Month(Date)
if iYear = 0 then iYear = Year(Date)
Call ShowHeader (iMonth, iYear)
FirstDay = WeekDay(DateSerial(iYear, iMonth, 1)) -1
CurrentDay = 1
DIM sWeekDay, iRows
sWeekDay = WeekDay(DateSerial(iYear, iMonth, 1))
IF sWeekDay <= 5 and LastDay(iMonth, iYear) >= 30 THEN
iRows = 4
ELSEIF sWeekDay =1 and iMonth = 2 THEN
iRows = 3
ELSEIF iMonth = 2 THEN
iRows = 4
ELSE
iRows = 5
END IF
For Row = 0 to iRows
For Col = 0 to 6
If Row = 0 and Col < FirstDay then
response.write "<td bgcolor='FFFFFF'> </td>"
elseif CurrentDay > LastDay(iMonth, iYear) then
response.write "<td bgcolor='FFFFFF'> </td>"
else
response.write "<td"
if iMonth = Month(Date) and CurrentDay = Day(Date) and iYear =
Year(Date)then
response.write " bgcolor='#CCCCCC' align='center'>"
else
response.write " align='center' bgcolor='FFFFFF'>"
end if
%>
<a href="ASP_calendar.asp?view=archive&day=<%=CurrentDay%>&month=<%=iMonth%>&year=<%=iYear%>"><%=CurrentDay%></a></td>
<%
'response.write CurrentDay & "</td>"
CurrentDay = CurrentDay + 1
End If
Next
response.write "</tr>"
Next
response.write "</table>"
'------ Sub and functions
Sub ShowHeader(iMonth,iYear)
%>
<div align="center">
<table border='0' cellspacing='1' cellpadding='2' width='200'
bgcolor="#000080" >
<tr align='center'>
<td colspan='7' bgcolor="FFFFFF">
<table border='0' cellspacing='0' cellpadding='2' width='100%'
bgcolor="FFFFFF" >
<tr>
<td align='left' >
<%
'********************** Prev Month
response.write "<a title='Prev Month' href = 'ASP_calendar.asp?view="&Request.QueryString("view")&"&day="&Request.QueryString("day")&"&"
if iMonth - 1 = 0 then
response.write "month=12&year=" & iYear -1
else
response.write "month=" & iMonth - 1 & "&year=" & iYear
end if
response.write "' ><<</a>"
%>
</td><td align='center' bgcolor="FFFFFF" >
<a title="Select month- <%=MonthName(iMonth)%>" href="ASP_calendar.asp?view=theMonth&month=<%=iMonth%>&year=<%=iYear%>"><%=MonthName(iMonth)
&" "& iYear%></a>
</td><td align='right' >
<%
'********************** Next Month
response.write "<a title='Next Month' href = 'ASP_calendar.asp?view="&Request.QueryString("view")&"&day="&Request.QueryString("day")&"&"
if iMonth + 1 = 13 then
response.write "month=1&year=" & iYear + 1
else
response.write "month=" & iMonth + 1 & "&year=" & iYear
end if
response.write "' >>></a>"
%>
</td></tr></table>
</td>
</tr>
<tr align='center' >
<td bgcolor="#C0C0C0"><font color="#FF0000"><b><i>S</i></b></font></td>
<td bgcolor="#C0C0C0"><font color="#FF0000"><b><i>M</i></b></font></td>
<td bgcolor="#C0C0C0"><font color="#FF0000"><b><i>T</i></b></font></td>
<td bgcolor="#C0C0C0"><font color="#FF0000"><b><i>W</i></b></font></td>
<td bgcolor="#C0C0C0"><font color="#FF0000"><b><i>T</i></b></font></td>
<td bgcolor="#C0C0C0"><font color="#FF0000"><b><i>F</i></b></font></td>
<td bgcolor="#C0C0C0"><font color="#FF0000"><b><i>S</i></b></font></td>
</tr>
<%
End Sub
Function LastDay(iMonth, iYear)
' Returns the last day of the month. Takes into account leap
years
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
LastDay = 31
Case 4, 6, 9, 11
LastDay = 30
Case 2
If IsDate(iYear & "-" & iMonth & "-" & "29") Then LastDay = 29
Else LastDay = 28
Case Else
LastDay = 0
End Select
End Function
%>
</div>
<table border='0' cellspacing='1' cellpadding='1' width='100%' >
<tr><td align='center' >
<a href="ASP_calendar.asp?view=archiveMonth&month=<%=month(now)%>&year=<%=year(now)%>">Current
Month</a>
</td>
</tr>
</table>
|
|