请问有没有用年和月表示日期的!

liaogs 2002-01-05 10:00:47
我想查出两个月之间的记录,该怎么查呢?
...全文
83 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liaogs 2002-01-05
  • 打赏
  • 举报
回复
是不是没有别的办法,一定要进行判断呀?
希偌 2002-01-05
  • 打赏
  • 举报
回复
以下,自己研究:
<!--#include file="../conn.asp"-->

<%
year2=request("year")
month2=request("month")
date2=request("date")
year1=request("year1")
month1=request("month1")
date1=request("date1")
if cint(year2)>cint(year1) then
response.write "<script>alert('起始时间应该小于终结时间!');history.back();</script>"
elseif cint(year2)=cint(year1) and cint(month2)>cint(month1) then
response.write "<script>alert('起始时间应该小于终结时间!');history.back();</script>"
elseif cint(year2)=cint(year1) and cint(month2)=cint(month1) and cint(date2)>cint(date1) then
response.write "<script>alert('起始时间应该小于终结时间!');history.back();</script>"
end if
if month2="2" then
if (cint(year2) mod 4)<>0 and cint(date2)>28 then
response.write "<script>alert('请选择正确的时间!');history.back();</script>"
elseif (cint(year2) mod 4)=0 and cint(date2)>29 then
response.write "<script>alert('请选择正确的时间!');history.back();</script>"
end if
end if
if month1="2" then
if (cint(year1) mod 4)<>0 and cint(date1)>28 then
response.write "<script>alert('请选择正确的时间!');history.back();</script>"
elseif (cint(year1) mod 4)=0 and cint(date1)>29 then
response.write "<script>alert('请选择正确的时间!');history.back();</script>"
end if
end if
if month2="4" or month2="6" or month2="9" or month2="11" then
if date2="31" then
response.write "<script>alert('请选择正确的时间!');history.back();</script>"
end if
end if
if month1="4" or month1="6" or month1="9" or month1="11" then
if date1="31" then
response.write "<script>alert('请选择正确的时间!');history.back();</script>"
end if
end if
straccess="select * from law where (addtime between CONVERT(datetime(8), '" & year2 & "-" & month2 & "-" & date2 & " 00:00:00') and CONVERT(datetime(8),'" & year1 & "-" & month1 & "-" & date1 & " 00:00:00'))"
set rst=server.createobject("adodb.recordset")
rst.cursortype=1
rst.locktype=3
rst.open straccess,conn
do while not rst.eof
rst.delete
rst.updatebatch
rst.movenext
loop
rst.close
set rst=nothing
response.write "<script>alert('成功删除!');window.location.href='manage2.asp';</script>"
%>
希偌 2002-01-05
  • 打赏
  • 举报
回复
给个例子你看看:
straccess="select * from law where (addtime between CONVERT(datetime(8), '" & year2 & "-" & month2 & "-" & date2 & " 00:00:00') and CONVERT(datetime(8),'" & year1 & "-" & month1 & "-" & date1 & " 00:00:00'))"
csdn_study 2002-01-05
  • 打赏
  • 举报
回复
你可以判斷一下,要查的那一年的哪一個月,如果是大月應該有31天,如果是小月應該有30天,而如果是2月份,還要分二種情況是平年還是閏年.這樣才好進行查詢.
liaogs 2002-01-05
  • 打赏
  • 举报
回复
用between或者<,>好想不好解决的,应为一个月的最后一天是个不确定的数字。可能是28,29,30,31

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧