ASP+SQL Server 對日期(查詢)處理總結

SQL Server:日期時間段
select * from student where bmrq >= '2011-5-1' and bmrq <=

'2011-5-7'

ASP關於日期的常用函數:

<%
'取某一週
'weekday(<日期表達式>) 週日返回1,週二返回2
a=date() - weekday(date()) - 5'取週一
b=a+6                          '取週日
response.write("本週:"&a&"至"&b)
%>

<%
'取某一月
y = year(date())
m = month(date())
s = y&"-"&m&"-"&"1"
s = cdate(s)      '每個月的第一個
d = y&"-"&(m+1)&"-"&"1"
d = cdate(d) - 1  '每個月的最後一天
response.write("本月:"&s&"至"&d)
%>

根據服務器日期生成可選擇月份
<%
'開始日期
s_date = cdate("2011-04-01")
txt = ""

txt = txt&"<select name='s_year'>"
for i = year(s_date) to year(date())
  txt = txt&"  <option value='"&i&"'>"&i&"</option>"
next
txt = txt&"</select>年"

txt = txt&"<select name='s_month'>"
if year(s_date) = year(date()) then
  for i = month(s_date) to month(date())
    txt = txt&"  <option value='"&i&"'>"&i&"</option>"
  next
else
  for i = 1 to 12
    txt = txt&"  <option value='"&i&"'>"&i&"</option>"
  next
end if
txt = txt&"</select>月"
response.write txt
%>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章