Code:
<%@ LANGUAGE=VBScript %> <% wYear=Request.QueryString("wYear") IF wYear = "" THEN wYear=Request.Form("wYear") IF wYear = "" OR wYear < 1753 OR wYear > 9999 THEN wYear = DATEPART("yyyy",now()) %> <html><HEAD><TITLE>SQL Calendar</TITLE></head> <BODY><CENTER> <form action="calendar.asp" method="post"> Enter a year from 1753 to 9999:<br> <input size=6 maxlength=4 name=wYear><br> <input type="submit" name="Change" VALUE="Change"> </form><BR> <H2><%=wYear%> Calendar</H2><P> <TABLE ALIGN=center WIDTH=30% BORDER=1 CELLSPACING=1 CELLPADDING=2> <TR> <TD ALIGN=middle></TD> <TD ALIGN=middle><STRONG>Sun.</STRONG></TD> <TD ALIGN=middle><STRONG>Mon.</STRONG></TD> <TD ALIGN=middle><STRONG>Tue.</STRONG></TD> <TD ALIGN=middle><STRONG>Wed.</STRONG></TD> <TD ALIGN=middle><STRONG>Thu.</STRONG></TD> <TD ALIGN=middle><STRONG>Fri.</STRONG></TD> <TD ALIGN=middle><STRONG>Sat.</STRONG></TD> </TR> <% mc = 0 FOR mc = 1 TO 12 %> <TR> <TD ALIGN=middle><STRONG><%=MonthName(mc)%></STRONG></TD> <% 'Determine day of the week the month begins on tempdate = mc & "/1/" & wYear bwdom = datepart("w", tempdate) DayOfWeekCounter = 0 'This "week" has 8 "days" to include the Name of the Month column. 'PRINT LEADING BLANK DAYS SELECT CASE bwdom CASE 1 DayOfWeekCounter = 1 CASE 2 %> <TD></TD><%DayOfWeekCounter = 2 CASE 3 %> <TD></TD><TD></TD><%DayOfWeekCounter = 3 CASE 4 %> <TD></TD><TD></TD><TD></TD><%DayOfWeekCounter = 4 CASE 5 %> <TD></TD><TD></TD><TD></TD><TD></TD><%DayOfWeekCounter = 5 CASE 6 %> <TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><%DayOfWeekCounter = 6 CASE 7 %> <TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><TD></TD><%DayOfWeekCounter = 7 CASE ELSE %> <TD>Beginning Day of Week Error</TD><% END SELECT 'Determine last day of month & number of weeks IF mc < 12 THEN ldom = Day(DateAdd("d", -1, mc + 1 & "/1/" & wYear)) ELSE ldom = Day(DateAdd("d", -1, "1/1/" & wYear + 1)) END IF NumWeeks = 5 IF (bwdom = 6 AND ldom = 31) OR (bwdom = 7 AND ldom > 29) THEN NumWeeks = 6 DayCounter = 1 WeekCounter = 1 DO WHILE WeekCounter < NumWeeks + 1 DO WHILE DayOfWeekCounter < 8 IF DayCounter < ldom + 1 THEN %> <TD ALIGN=middle><STRONG><%=DayCounter%></STRONG></TD> <% 'IF statements for holidays and anniversaries goes here. %> <%ELSE%> <TD ALIGN=middle></TD> <%END IF DayOfWeekCounter = DayOfWeekCounter + 1 DayCounter = DayCounter + 1 LOOP DayOfWeekCounter = 1 WeekCounter = WeekCounter + 1 %> </TR><TR><TD></TD> <%LOOP%> <%NEXT%> </TABLE><P> </center></BODY></HTML>