Jan 26

Month Calendar Cenerator Function (monthCalendar)

Generates an HTML calendar for a single month containing ‘thisDate’.

function monthCalendar(thisDate)
	today = split(formatdatetime(thisDate,2),"/")

	m = today(0)
	y = today(2)

	response.write("<table cellspacing='0' cellpadding='0' width='110px' height='100px' border='1'>")
		response.write("<tr><td colspan='7' align='center'><div>" & monthname(m) & " " & y & "</div></td></tr>")
		response.write("<tr>")
			mday = 1
			row = 1
			start = 0
			
			for i = 1 to 7
				if i = weekday(m & "/01/" & y) then
					start = 1	
				end if
				if start = 1 then
					if int(today(1)) = int(mday) then
						response.write("<td align='center'><div>" & mday & "</div></td>")
					else
						response.write("<td align='center'><div>" & mday & "</div></td>")
					end if
					mday = mday + 1
				else
					response.write("<td><div> :</div></td>")
				end if
			next
			
			if int(m) < 12 then
				lastdaytemp = split((cdate(m+1 & "/01/" & y) - 1),"/")
				lastday = lastdaytemp(1)
			else
				lastday = 31
			end if
			
			wd = 1
			row = 2
			
			for i = mday to lastday
				if wd = 1 then
					response.write("<tr>")
				elseif wd = 8 then
					response.write("</tr>")
					wd = 1
					row = row + 1
				end if
				if int(today(1)) = int(i) then
					response.write("<td align='center'><div>" & i & "</div></td>")
				else
					response.write("<td align='center'><div>" & i & "</div></td>")
				end if
				wd = wd + 1
			next
			do while wd <> 8
				response.write("<td><div> :</div></td>")
				wd = wd + 1
			loop
		response.write("</tr>")
	response.write("</table>")
end function

Permanent link to this article: https://www.wperry.net/code/monthcalendar/

Leave a Reply

Your email address will not be published.