ASP日历 实现遍历数据库取出对应的年月日数据
2009-05-04 11:11:56 来源:WEB开发网<%@LANGUAGE="VBSCRipT" CODEPAGE="65001"%>
<%
response.charset = "UTF-8"
session.codepage = 65001
session.timeout = 1440
server.scripttimeout = 9999
%>
<!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=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<title>纯asp日历</title>
<style>
body{font-size:12px; margin:20px 0 0 20px; padding:0}
tr,td{text-align:center;}
</style>
</head>
<body>
<%
'=================================
'说明:日历文件
'=================================
'取出对应的年月日数据
'=======================
Ryear = CInt(request.querystring("year"))
Rmonth = CInt(request.querystring("month"))
If Ryear = 0 or Ryear = NULL Then Ryear = year(now)
If Rmonth = 0 or Rmonth = NULL Then Rmonth = month(now)
nowtime = Ryear&"-"&Rmonth&"-1" '得到本月第一天
nowyear = year(nowtime) '年份
nowmonth = month(nowtime) '月份
nowweekday = weekday(nowtime) - 1 '当前礼拜
'获取2月天数
febdays = 28
If nowyear / 4 = 0 Then febdays = 29
'获取本月天数
If nowmonth = 1 then
monthdays = 31
ElseIf nowmonth = 2 Then
monthdays = febdays
ElseIf nowmonth = 3 Then
monthdays = 31
ElseIf nowmonth = 4 Then
monthdays = 30
ElseIf nowmonth = 5 Then
monthdays = 31
ElseIf nowmonth = 6 Then
monthdays = 30
ElseIf nowmonth = 7 Then
monthdays = 31
ElseIf nowmonth = 8 Then
monthdays = 31
ElseIf nowmonth = 9 Then
monthdays = 30
ElseIf nowmonth = 10 Then
monthdays = 31
ElseIf nowmonth = 11 Then
monthdays = 30
Else
monthdays = 31
End If
calendar = "<a href='calendar.asp?year="&nowyear - 1&"&month="&nowmonth&"'> <<</a> "
willshowmonthmonth = nowmonth
If willshowmonthmonth - 1 <= 0 Then willshowmonthmonth = 2
calendar = calendar & "<a href='calendar.asp?year="&nowyear&"&month="&willshowmonthmonth - 1&"'> <</a> "
If willshowmonthmonth + 1 > 12 Then willshowmonthmonth = 11
calendar = calendar & "<a href='calendar.asp?year="&nowyear&"&month="&willshowmonthmonth + 1&"''> ></a> "
calendar = calendar & "<a href='calendar.asp?year="&nowyear + 1&"&month="&nowmonth&"'> >></a> "
calendar = calendar & "<table bgcolor=#000000 cellspacing=1 width=200><tr bgcolor=#ffffff><td colspan=7>"&nowyear&"-"&nowmonth&"-"&day(now)&"</td></tr>"&VBCRLF
calendar = calendar & " <tr bgcolor=#ffffff>"&VBCRLF
calendar = calendar & "<td>日</td>"&VBCRLF
calendar = calendar & "<td>一</td>"&VBCRLF
calendar = calendar & "<td>二</td>"&VBCRLF
calendar = calendar & "<td>三</td>"&VBCRLF
calendar = calendar & "<td>四</td>"&VBCRLF
calendar = calendar & "<td>五</td>"&VBCRLF
calendar = calendar & "<td>六</td>"&VBCRLF
calendar = calendar & "</tr>"&VBCRLF
calendar = calendar & VBCRLF&"<tr bgcolor=#ffffff>"&VBCRLF
'http://www.cncms.com/ 把前面的空白补充出来
nowmonthfirstiweekday = weekday(nowyear&"-"&nowmonth&"-1") - 2 '本月第一天的星期
For i=0 To nowmonthfirstiweekday
calendar = calendar & "<td bgcolor=#efefef> </td>"&VBCRLF
Next
'开始循环写日期
t=1
For i=1 To monthdays
If year(now) = year(nowyear&"-"&nowmonth&"-"&i) and day(now) = day(nowyear&"-"&nowmonth&"-"&i) Then '高亮显示今日
calendar = calendar & "<td bgcolor=#cccccc><a href=''>"&i&"</a></td>"&VBCRLF
Else
calendar = calendar & "<td>"&i&"</td>"&VBCRLF
End If
If weekday(nowyear&"-"&nowmonth&"-"&i) = 7 Then
t=t+1
calendar = calendar & "</tr><tr bgcolor=#ffffff>"&VBCRLF
End if
Next
For i=1 To (7*t-(nowmonthfirstiweekday+1+monthdays))
calendar = calendar & "<td bgcolor=#ffffff></td>"&VBCRLF
Next
calendar = calendar & VBCRLF&"</tr>"
calendar = calendar & "</table>"&VBCRLF
Response.Write calendar
%>
</body>
</html>
更多精彩
赞助商链接