根据时间段查询数据的问题

xuheguan 2002-04-12 11:56:36
我如何赋两个初始值查询,即一个当前日期和当前日期以前一个月的时间段查询,这样速度较快,另要输入非日期格式显示无记录而不出错,谢谢
...全文
23 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuzxit 2002-04-12
  • 打赏
  • 举报
回复
在ASP中以下函数
判断日期是否有效﹔isdate()
获取今天﹕date()
今天的前一个月﹕DateAdd("m",-1,date())
hubinasm 2002-04-12
  • 打赏
  • 举报
回复
<%@language=vbscript%>
<% 'response.buffer=true %>
<%'On Error Resume Next%>
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=gb_2312-80">
<script language="JavaScript">
<!--
function changeSelectDay(x){
var yy,mm,dd;
var i,j;
if (x == 1)
{
yy=parseInt(document.hamier2.start_year.value);
mm=parseInt(document.hamier2.start_month.value);
i=document.hamier2.start_day.options.length;
}
else if (x == 2)
{
yy=parseInt(document.hamier2.end_year.value);
mm=parseInt(document.hamier2.end_month.value);
i=document.hamier2.end_day.options.length;
}

dd=getDay(yy,mm);

if (dd!=0){
if (dd>i){

if (x == 1){
for(j=i;j<dd;j++){
document.hamier2.start_day.options[j]=new Option(j+1,j+1);
}
}
else if (x == 2){
for(j=i;j<dd;j++){
document.hamier2.end_day.options[j]=new Option(j+1,j+1);
}
}

}
else if(dd<i){

if (x == 1) {
for(j=i;j>dd;j--){
document.hamier2.start_day.options[j-1]=null;
}
}
else if (x ==2){
for(j=i;j>dd;j--){
document.hamier2.end_day.options[j-1]=null;
}
}


}
}
}
function getDay(yy,mm){
//((n mod 4=0) and (n mod 100<>0)) or (n mod 400=0))
var iyear,imonth;
iyear=parseInt(yy);
imonth=parseInt(mm);
switch (imonth){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
break;
case 4:
case 6:
case 9:
case 11:
return 30;
break;
case 2:
if(((iyear%4==0) && (iyear%100!=0)) || (iyear%400==0))
return 29;
else
return 28;
break;
default:
return 0;
break;
}
}

function fanhui()
{
window.location.href="writermanage.asp";
}

// -->
</script>
</head>

<body topmargin="0">

<%
year_now =year(date())
month_now = month(date())
day_now = day(date())
%>
<font color=blue>

<form method="POST" action="baobiao_in_view.asp" name="hamier2">
<p align=center><font color=red>请在以下的表格中选择相关的查询条件</font>
<p> <table align=center border=0>
<tr>
<td nowrap>起始日期:</td>
<td>
<select name="start_year" onchange="javascript:changeSelectDay(1)">
<%for i=2001 to 2008 %>
<%
if cint(i) = cint(year_now) then
%>
<option selected value="<%Response.Write i%>" ><%Response.Write i%></option>
<%else%>
<option value="<%Response.Write i%>" ><%Response.Write i%></option>
<%end if%>

<%next%>
</select>年


<select name="start_month" onchange="javascript:changeSelectDay(1)">
<% for i=1 to 12%>
<%
if cint(i) = cint(month_now) then %>
<option selected value="<%Response.Write i%>" ><%Response.Write i%></option>
<%else%>
<option value="<%Response.Write i%>" ><%Response.Write i%></option>
<%end if%>
<%next%>
</select>月
<select name="start_day" onchange="javascript:changeSelectDay(1)">
<% for i=1 to 31%>
<%
if cint(i) = cint(day_now) then %>
<option selected value="<%Response.Write i%>" ><%Response.Write i%></option>
<%else%>
<option value="<%Response.Write i%>" ><%Response.Write i%></option>
<%end if%>
<%next%>
</select>日
</td>
<td>
</td>
</tr>
<tr>
<td nowrap>截止日期:</td>
<td>
<select name="end_year" onchange="javascript:changeSelectDay(2)">
<%for i=2001 to 2008 %>
<%
if cint(i) = cint(year_now) then
%>
<option selected value="<%Response.Write i%>" ><%Response.Write i%></option>
<%else%>
<option value="<%Response.Write i%>" ><%Response.Write i%></option>
<%end if%>

<%next%>
</select>年


<select name="end_month" onchange="javascript:changeSelectDay(2)">
<% for i=1 to 12%>
<%
if cint(i) = cint(month_now) then %>
<option selected value="<%Response.Write i%>" ><%Response.Write i%></option>
<%else%>
<option value="<%Response.Write i%>" ><%Response.Write i%></option>
<%end if%>
<%next%>
</select>月
<select name="end_day" onchange="javascript:changeSelectDay(2)">
<% for i=1 to 31%>
<%
if cint(i) = cint(day_now) then %>
<option selected value="<%Response.Write i%>" ><%Response.Write i%></option>
<%else%>
<option value="<%Response.Write i%>" ><%Response.Write i%></option>
<%end if%>
<%next%>
</select>日
</td> </tr>


<tr>
<td>
<td><br><input class=buttonface type=submit name=ok value=查询> 
<input class=buttonface type=button name=retu value=返回 onclick="fanhui()">
</tr>
</table>
</form>
</body>
</html>
heeh 2002-04-12
  • 打赏
  • 举报
回复
on error resume next
select * from table where convert(char(8),datecol,112)<convert(char(8),getdate(),112) and convert(char(8),datecol,112)>convert(char(8),dateadd(m,-1,getdate()),112)

28,391

社区成员

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

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