<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Asp 日历控件</title>
</head>
<body>
<%
'----------------------------------------------------------------------------------
'Asp 日历控件 Calendar(CurrentDate,IsForward,IsBack)
'参数CurrentDate为日历当前时间,IsForward为true 时显示CurrentDate的前一个月
'IsBack为true显示CurrentDate的后一个月
'示例：CurrentDate=Trim(Request("ReqDate")):Calendar CurrentDate,false,false
'----------------------------------------------------------------------------------
sub Calendar(CurrentDate,IsForward,IsBack)
If Trim(CurrentDate)="" or ( not IsDate(Trim(CurrentDate)) ) then
CurrentDate=Date
end if
PreviousMonthDate=DateAdd("m",-1,CurrentDate)
NextMonthDate=DateAdd("m",1,CurrentDate)
if IsForward then
CurrentDate=dateadd("m",1,CurrentDate)
elseif IsBack then 
CurrentDate=dateadd("m",-1,CurrentDate)
end if
%>
<table width="180" cellpadding="0" cellspacing="1" bgcolor="dddddd" align="center" style="float:left">
<tr align="left" bgcolor="#dddddd"> 
    <td width="14%" height="20"><input type="button" value="<<" onclick="JavaScript:window.location.href='?ReqDate=<%=PreviousMonthDate%>'"></td>
    <td colspan="5" align="center"><%=year(CurrentDate)&"年"&month(CurrentDate)&"月"%></td>
    <td width="14%"><input type="button" value=">>" onclick="JavaScript:window.location.href='?ReqDate=<%=NextMonthDate%>'"></td>
</tr>
<tr align="center" bgcolor="#CCCCCC"> 
    <td width="14%" height="20"> 日</td>
    <td width="14%"> 一</td>
    <td width="14%"> 二</td>
    <td width="14%"> 三</td>
    <td width="14%"> 四</td>
    <td width="14%"> 五</td>
    <td width="14%"> 六</td>
</tr>
<%
ym=year(CurrentDate)&"-"&month(CurrentDate)&"-"
i=1
currentMonthDays=datediff("d",CurrentDate,dateadd("m",1,CurrentDate))
do while i<currentMonthDays+1
   j=1
   response.write("<tr bgcolor=""ffffff"" height=""20"">")
   do while j<8
    If IsDate(ym&i) then
       CurrentWeekDay=weekday(ym&i)
      if j=CurrentWeekDay then
        If Datediff("d",ym&i,now)>-1 then
         LinkText="<a href=""http://www.house592.com"" target=""_blank"">"&i&"</a>"
        else
          LinkText=i
        end if
        if i<>Day(now) then
          response.write("<td>&nbsp;"&LinkText&"</td>")
        else
          response.write("<td bgcolor=""ffaaaa"">&nbsp;"&LinkText&"</td>")    
        end if
        i=i+1
       else
        response.write("<td></td>")
       end if
     else
       response.write("<td>&nbsp;</td>")
       i=i+1
       'exit do
     end if
     j=j+1
   loop
   response.write("</tr>"&vbcrlf) 
loop
%>
</table>
<%
end sub
'调用示例
CurrentDate=Trim(Request("ReqDate")):Calendar CurrentDate,false,false
%>
</body>
</html>