asp搜索日期范围代码怎么写
如果提交的页面代码如下:<formname="form1"method="post"action="xiaofeijilu.asp">贵宾姓名:<inputtype=te...
如果提交的页面代码如下: <form name="form1" method="post" action="xiaofeijilu.asp">
贵宾姓名:<input type=text name="xingming" size="30">
开始时间:<input type=text name="date1" size="30">
结束时间:<input type=text name="date2" size="30">
<input type="submit" name="Submit2" value="查询记录">
</form>
以下代码应该修改什么地方才能搜索到指定的时间范围?
<%
set rs=Server.CreateObject("ADODB.RecordSet")
sql="select * from vipback where online='1' "
xingming=request("xingming")
date1=request("date1")
date2=request("date2")
sql=sql+ " and xingming like '%"&xingming&"%'"+" and postdate like '%"&date1&"%' " ///这里应该怎么修改才对
sql=sql + "order by top desc,id desc"
rs.open sql,conn,1
%> 展开
贵宾姓名:<input type=text name="xingming" size="30">
开始时间:<input type=text name="date1" size="30">
结束时间:<input type=text name="date2" size="30">
<input type="submit" name="Submit2" value="查询记录">
</form>
以下代码应该修改什么地方才能搜索到指定的时间范围?
<%
set rs=Server.CreateObject("ADODB.RecordSet")
sql="select * from vipback where online='1' "
xingming=request("xingming")
date1=request("date1")
date2=request("date2")
sql=sql+ " and xingming like '%"&xingming&"%'"+" and postdate like '%"&date1&"%' " ///这里应该怎么修改才对
sql=sql + "order by top desc,id desc"
rs.open sql,conn,1
%> 展开
4个回答
展开全部
sql数据库如下
xingming=request("xingming")
date1=request("date1")
date2=request("date2")
Dim SearchSQL
If xingming <> "" Then
SearchSQL = SearchSQL & " and xingming like '%" & xingming & "%'"
End If
If IsDate(date1) Then
SearchSQL = SearchSQL & " and Datediff(s,'" & date1 & "',postdate) > 0"
End If
If IsDate(date2) Then
SearchSQL = SearchSQL & " and Datediff(s,'" & date2 & "',postdate) < 0"
End If
sql="select * from vipback where online='1' " & SearchSQL & " order by top desc,id desc"
xingming=request("xingming")
date1=request("date1")
date2=request("date2")
Dim SearchSQL
If xingming <> "" Then
SearchSQL = SearchSQL & " and xingming like '%" & xingming & "%'"
End If
If IsDate(date1) Then
SearchSQL = SearchSQL & " and Datediff(s,'" & date1 & "',postdate) > 0"
End If
If IsDate(date2) Then
SearchSQL = SearchSQL & " and Datediff(s,'" & date2 & "',postdate) < 0"
End If
sql="select * from vipback where online='1' " & SearchSQL & " order by top desc,id desc"
追问
我用的是access数据库,一楼的朋友是不是语法有问题,把sql换成您给的反而在不搜索的时候也显示不出来数据了
二楼的朋友能不能说说access的语句应该怎么写
追答
把Datediff(s,'" & date1 & "',postdate) > 0中的s用单引号引起来就可以了
如SearchSQL = SearchSQL & " and Datediff('s','" & date1 & "',postdate) > 0"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
exec="select * from ruku where EQ_code like '%"&EQ_code&"%' and riqi between '2009-2-1' and '2009-2-28'
设一个日期范围,用between and查询可以了
设一个日期范围,用between and查询可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
xingming=request("xingming")
date1=request("date1")
date2=request("date2")
Dim SearchSQL
If xingming <> "" Then
SearchSQL = SearchSQL & " and xingming like '%" & xingming & "%'"
End If
If IsDate(date1) Then
SearchSQL = SearchSQL & " and Datediff('s','" & date1 & "',postdate) > 0"
End If
If IsDate(date2) Then
SearchSQL = SearchSQL & " and Datediff('s','" & date2 & "',postdate) < 0"
End If
sql="select * from vipback where online='1' " & SearchSQL & " order by top desc,id desc"
date1=request("date1")
date2=request("date2")
Dim SearchSQL
If xingming <> "" Then
SearchSQL = SearchSQL & " and xingming like '%" & xingming & "%'"
End If
If IsDate(date1) Then
SearchSQL = SearchSQL & " and Datediff('s','" & date1 & "',postdate) > 0"
End If
If IsDate(date2) Then
SearchSQL = SearchSQL & " and Datediff('s','" & date2 & "',postdate) < 0"
End If
sql="select * from vipback where online='1' " & SearchSQL & " order by top desc,id desc"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询