<html> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=gb2312" /> 
<title>日历</title ></head> 
<body bgcolor="#ffffff"> 
<style>
td{font-size:9pt;}
</style>
<% 
' 要调用的函数声明 
'根据年份及月份得到每月的总天数 
function getdaysinmonth(imonth, iyear) 
select case imonth 
case 1, 3, 5, 7, 8, 10, 12 
getdaysinmonth = 31 
case 4, 6, 9, 11 
getdaysinmonth = 30 
case 2 
if isdate("february 29, " & iyear) then 
getdaysinmonth = 29 
else 
getdaysinmonth = 28 
end if 
end select 
end function 
'得到一个月开始的日期. 
function getweekdaymonthstartson(danydayinthemonth) 
dim dtemp 
dtemp = dateadd("d", -(day(danydayinthemonth) - 1), danydayinthemonth) 
getweekdaymonthstartson = weekday(dtemp) 
end function 
'得到当前一个月的上一个月. 
function subtractonemonth(ddate) 
subtractonemonth = dateadd("m", -1, ddate) 
end function 
'得到当前一个月的下一个月. 
function addonemonth(ddate) 
addonemonth = dateadd("m", 1, ddate) 
end function 
' 函数声明结束 

dim ddate ' 日历显示的日期 
dim idow ' 每一月开始的日期 
dim icurrent ' 当前日期 
dim iposition ' 表格中的当前位置 


' 得到选择的日期并检查日期的合法性 
if isdate(request.querystring("date")) then 
ddate = cdate(request.querystring("date")) 
else 
if isdate(request.querystring("month") & "-" & request.querystring("day") & "-" & request.querystring("year")) then 
ddate = cdate(request.querystring("month") & "-" & request.querystring("day") & "-" & request.querystring("year")) 
else 
ddate = date() 

if len(request.querystring("month")) <> 0 or len(request.querystring("day")) <> 0 or len(request.querystring("year")) <> 0 or len(request.querystring("date")) <> 0 then 
response.write "您所选择的日期格式不正确，系统会使用当前日期.<br><br>" 
end if 

end if 
end if 

'得到日期后我们先得到这个月的天数及这个月的起始日期. 
idim = getdaysinmonth(month(ddate), year(ddate)) 
idow = getweekdaymonthstartson(ddate) 

%> 
<table width="180" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#f3f3f3">
<tr>
<td align="center" colspan="7"><table border="0" cellpadding="0" cellspacing="0"width="100%">
<tr>
<td height="22" align="right"><a href="?date=<%= subtractonemonth(ddate) %>"><<</a></td>
<td align="center"><font color="999999"><b><%= monthname(month(ddate)) & " " & year(ddate) %></b></font></td>
<td><a href="?date=<%= addonemonth(ddate) %>">>></a></td>
</tr>
</table></td>
</tr>
<tr>
<td width="25" height="22" align="center"><font color="d08c00"><b>日</b></font> </td>
<td width="25" align="center"><b><font color="999999">一</font></b> </td>
<td width="25" align="center"><b><font color="999999">二</font></b> </td>
<td width="25" align="center"><b><font color="999999">三</font></b> </td>
<td width="25" align="center"><b><font color="999999">四</font></b> </td>
<td width="25" align="center"><b><font color="999999">五</font></b> </td>
<td width="25" align="center"><b><font color="d08c00">六</font></b> </td>
</tr>
<% 
' 如果这个月的起始日期不是周日的话就加空的单元. 
if idow <> 1 then 
response.write vbtab & "<tr>" & vbcrlf 
iposition = 1 
do while iposition < idow 
response.write vbtab & vbtab & "<td> </td>" & vbcrlf 
iposition = iposition + 1 
loop 
end if 

' 绘制这个月的日历 
icurrent = 1 
iposition = idow 
do while icurrent <= idim 
' 如果是一行的开头就使用 tr 标记 
if iposition = 1 then 
response.write vbtab & "<tr>" & vbcrlf 
end if 

' 如果这一天是我们选择的日期就高亮度显示该日期. 
if icurrent = day(ddate) then 
response.write vbtab & vbtab & "<td bgcolor=#eeeeee height=18 align=center><b>" & icurrent & "</b></td>" & vbcrlf 
else 
response.write vbtab & vbtab & "<td height=18 align=center><a href=""?date=" & month(ddate) & "-" & icurrent & "-" & year(ddate) & """>" & icurrent & "</a></td>" & vbcrlf 
end if 

' 如果满一周的话表格就另起一行 
if iposition = 7 then 
response.write vbtab & "</tr>" & vbcrlf 
iposition = 0 
end if 

icurrent = icurrent + 1 
iposition = iposition + 1 
loop 

' 如果一个月不是以周六结束则加上相应的空单元. 
if iposition <> 1 then 
do while iposition <= 7 
response.write vbtab & vbtab & "<td> </td>" & vbcrlf 
iposition = iposition + 1 
loop 
response.write vbtab & "</tr>" & vbcrlf 
end if 
%>
</table>
