一、 DATEDIFF应用
SELECT raintime, DATEDIFF(hour, raintime, CAST('2006-11-20 01:00' AS datetime)) AS rt
FROM S_yuliang_zhengdian
WHERE (DATEADD(hour, 1, raintime) = CAST('2006-11-20 01:00' AS datetime))
二、javascript前一天后一天.txt
<SCRIPT LANGUAGE="JavaScript">
<!--
//alert('<%=ntime%>')
var now = new Date();
n0=now.getYear()
y0=now.getMonth()+1
d0=now.getDate()
h0="0"+now.getHours();
m0="0"+now.getMinutes();
s0="0"+now.getSeconds();
if(h0>9){h0=now.getHours()}
if(m0>9){m0=now.getMinutes()}
if(s0>9){s0=now.getSeconds()}
document.all.tb1.value = n0+"-"+y0+"-"+d0+" "+h0+":"+m0+":"+s0
DaysToAdd=0;
function predata_Click()
{
DaysToAdd=DaysToAdd-1;
var newdate=new Date(n0,y0,d0,h0,m0,s0);
var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
newdate.setTime(newtimems);
var xdate=newdate
var newh="0"+xdate.getHours()
var newm="0"+xdate.getMinutes()
var news="0"+xdate.getSeconds()
if(newh>9){newh=xdate.getHours()}
if(newm>9){newm=xdate.getMinutes()}
if(news>9){news=xdate.getSeconds()}
document.form.tb1.value=xdate.getYear()+"-"+xdate.getMonth()+"-"+xdate.getDate()+" "+newh+":"+newm+":"+news
frame2.src="./search/yuliangmview.asp"
}
function passdata_Click()
{
DaysToAdd=DaysToAdd+1;
var newdate=new Date(n0,y0,d0,h0,m0,s0);
var newtimems=newdate.getTime()+(DaysToAdd*24*60*60*1000);
newdate.setTime(newtimems);
var xdate=newdate
var newh="0"+xdate.getHours()
var newm="0"+xdate.getMinutes()
var news="0"+xdate.getSeconds()
if(newh>9){newh=xdate.getHours()}
if(newm>9){newm=xdate.getMinutes()}
if(news>9){news=xdate.getSeconds()}
document.form.tb1.value=xdate.getYear()+"-"+xdate.getMonth()+"-"+xdate.getDate()+" "+newh+":"+newm+":"+news
frame2.src="./search/yuliangmview.asp"
}
//-->
</SCRIPT>
三、javascript与VBSCRIPT前一天后一天
<!-- #include file= "CN.asa" -->
<%
dim ntime,pointtime
ntime=request("time")
ntime=cdate(ntime)
%>
<html>
<head><title></title>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="../images/css.css" type=text/css rel=stylesheet>
<script language="javascript" src="../clock/calendar.js"></script>
</head>
<style>
.td{
text-align: center;
}
</style>
<body leftmargin="0" topmargin="0" marginwidth="0" cellSpacing=0 cellPadding=0 >
<%
dim sql,idArray(),i,idlist,idlistor,namelist,namearray(),totalarray(),timearray(24),rtime(),rvolume(12),rstation(12)
dim single1,address,strtitle,strbody,strbottom,h1
h1=0
n=year(ntime)
y=month(ntime)
d=day(ntime)
nn=year(now)
ny=month(now)
nd=day(now)
h="08"
m="00"
s="00"
pointtime=n & "-" & y & "-" & d & " " & h & ":" & m &":" & s
strntime=n & "-" & y & "-" & d & " " & "00" & ":" & "00" &":" & "00"
strnow=nn & "-" & ny & "-" & nd & " " & "00" & ":" & "00" &":" & "00"
'response.write(strntime)
'response.write(strnow)
'dim newdate=new Date(n,y,d,h,m,s);
'dim newtimems=newdate.getTime()+((-1)*24*60*60*1000);
'newdate.setTime(newtimems);
'xdate=newdate
'newh="0"+xdate.getHours()
'newm="0"+xdate.getMinutes()
'news="0"+xdate.getSeconds()
'if(newh>9){newh=xdate.getHours()}
'if(newm>9){newm=xdate.getMinutes()}
'if(news>9){news=xdate.getSeconds()}
'newDate=xdate.getYear()+"-"+xdate.getMonth()+"-"+xdate.getDate()+" "+newh+":"+newm+":"+news
up=cdate(strntime)-cdate(strnow)
up=cint(up)
if(up=0) then
h1=hour(now)
if(h1>=9) then
h1=h1-8
newtime=cdate(pointtime)
else
h1=h1+15
newtime=cdate(pointtime)-1
end if
end if
if(up<0) then
h1=23
newtime=cdate(pointtime)-1
'response.write("小于0")
'response.write(h1)
'response.write(newtime)
end if
if(up>0) then
h1=-1
newtime=cdate(pointtime)
'response.write("大于0")
end if
strtitle=""
strbody=""
strbottom=""
address=request("address")
single1=" "
for i=8 to 24
if(i=23) then
timearray(i)="0"&i&":00-00:00"
else
timearray(i)="0"&i&":00-0"&(i+1)&":00"
end if
next
timearray(0)="08:00-09:00"
timearray(1)="09:00-10:00"
timearray(2)="10:00-11:00"
timearray(3)="11:00-12:00"
timearray(4)="12:00-13:00"
timearray(5)="13:00-14:00"
timearray(6)="14:00-15:00"
timearray(7)="15:00-16:00"
timearray(8)="16:00-17:00"
timearray(9)="17:00-18:00"
timearray(10)="18:00-19:00"
timearray(11)="19:00-20:00"
timearray(12)="20:00-21:00"
timearray(13)="21:00-22:00"
timearray(14)="22:00-23:00"
timearray(15)="23:00-00:00"
timearray(16)="00:00-01:00"
timearray(17)="01:00-02:00"
timearray(18)="02:00-03:00"
timearray(19)="03:00-04:00"
timearray(20)="04:00-05:00"
timearray(21)="05:00-06:00"
timearray(22)="06:00-07:00"
timearray(23)="07:00-08:00"
i=0
sql="select recon_id,name from T_yuliangzhan"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,cn,1,1
'response.write("选择查询站")
'response.write("<select id='idselect'>")
'response.write("<option >请选择</option>")
idlistor=""
do while not rs.eof
if(rs("recon_id")<>"") then
Redim preserve idArray(i)
Redim preserve namearray(i)
Redim preserve totalarray(i)
namearray(i)=rs("name")
idArray(i)=rs("recon_id")
idlist=idlist&rs("recon_id")&"|"
namelist=namelist&rs("name")&"|"
totalarray(i)=0
'response.write(idArray(i))
i=i+1
'response.write("<option value="&rs("recon_id")&">"&rs("name")&"</option>")
end if
rs.MoveNext()
loop
rs.close
idlistor="stationid = "+"'"+idArray(0)+"'"
for i=1 to UBound(idArray)
idlistor=idlistor&" or "&"stationid = "+"'"+idArray(i)+"'"
next
'response.write("</select>")
'response.write("<input type='checkbox' id='zhen'>")
'response.write("整点")
'response.write(UBound(idArray,1))
'response.write("数据时间:<input name='startdate' type='text' id='st' style='cursor:hand' onclick='showCal()' size=12>到:<input name='enddate' type='text' id='et' style='cursor:hand' onClick='showCal()' size=12><input type='button' onclick='linkdata()' value='执行查询'>")
response.write("<br> 雨量实时表")
response.write("<TABLE cellSpacing=0 borderColorDark=#e4edf3 cellPadding=4 width='70%' borderColorLight=#5999c8 border=1 align=center><tr style='font-color:#0055A5' bgcolor='#B7DAFA'><td align=center>站名</td><td align=center>时间</td><td align=center>降雨量(mm)</td></tr>")
for ii=0 to UBound(idArray)
'sql="select top 1 raintime,rainvolume from s_yuliang where stationid='"&idArray(ii)&"' order by raintime desc"
if((cdate(now)-cdate(ntime))>=0 and (cdate(now)-cdate(ntime))<1/144) then
sql="select top 1 raintime,rainvolume from s_yuliang where stationid='"&idArray(ii)&"' order by raintime desc"
else
sql="select top 1 raintime,rainvolume from s_yuliang where stationid='"&idArray(ii)&"' and raintime >'"&(cdate(ntime)-1/288)&"'and raintime <'"&(cdate(ntime)+1/288)&"'order by raintime desc"
end if
rs.open sql,cn
if not rs.eof then
response.write("<tr><tr><td align=center>"&namearray(ii)&"</td><td align=center>"&rs("raintime")&single1&"</td><td align=center>"&rs("rainvolume")&single1&"</td></tr></tr>")
end if
rs.close
next
response.write("</table>")
response.write("<br>")
response.write(" 雨量整点表(单位:mm)")
'顶部站点
for ii=0 to UBound(idArray)
strtitle=strtitle&"<td align=center>"&namearray(ii)&"</td>"
next
response.write("<TABLE cellSpacing=0 borderColorDark=#e4edf3 cellPadding=4 width='70%' borderColorLight=#5999c8 border=1 align=center><tr style='font-color:#0055A5' bgcolor='#B7DAFA'><td align=center>时间</td>"+strtitle+"</tr>")
'中间雨量
h1=cint(h1)-8+8
for ii=0 to h1
strbody=""
newtime=newtime+1/24
for i=0 to UBound(idArray)
sql="select stationid,rainvolume from s_yuliang_zhengdian where raintime ='"&newtime&"'and stationid='"&idArray(i)&"'"
rs.open sql,cn
if not rs.eof then
rvolume(i)=rs("rainvolume")
rstation(i)=rs("stationid")
if(rs("stationid")="" or rs("stationid")=null) then
rvolume(i)=0
rstation(i)=idArray(i)
end if
end if
rs.close
next
for iii=0 to UBound(idArray)
totalarray(iii)=totalarray(iii)+rvolume(iii)
if(rvolume(iii)="" or rvolume(iii)=null) then
strbody=strbody&"<td align=center>0</td>"
else
strbody=strbody&"<td align=center>"&rvolume(iii)&"</td>"
end if
next
response.write("<tr><tr><td align=center>"&timearray(ii)&"</td>"+strbody+"</tr></tr>")
next
'底部总量
for ii=0 to UBound(idArray)
if((totalarray(ii)<1) and (totalarray(ii)>0)) then
strtotal=0&cstr(totalarray(ii))
strbottom=strbottom&"<td align=center>"&strtotal&"</td>"
else
strbottom=strbottom&"<td align=center>"&totalarray(ii)&"</td>"
end if
next
response.write("<tr><tr><td align=center>总计</td>"+strbottom+"</tr>")
response.write("</table>")
set rs=nothing
cn.close
set cn=nothing
%>
<form name="f1" method="post">
<table width="100%">
<tr><td align=center>
<!-- onclick="callpreviousDay()"onclick="callnextDay()" -->
<input type="button" name="predata" value="前一天" style="width: 57px;
height: 20px" OnClick="CallPreviousDay()" >
<input name="tb1" type="text" value='<%=request("time")%>' style="width: 140px;
height: 20px;text-align: center;" onclick='seldate()' />
<input type="button" name="passdata" value="后一天" style="width: 57px;
height: 20px" OnClick="CallNextDay()" >
</tr>
</table>
</form>
<script language="javascript" type="text/javascript">
idlist='<%=idlist%>'
namelist='<%=namelist%>'
address='<%=address%>';
idarray=idlist.split("|")
namearray=namelist.split("|")
var zheng=parent.document.getElementById("zhengdian")
zheng.style.display="inline"
parent.document.getElementById("zhengdian1").style.display="inline"
var zhandian=parent.document.getElementById("zhandian")
if(zhandian.options.length>0){
//for(i=0;i<zhandian.options.length;i++){
// zhandian.options[i].remove(true)
//
// }
zhandian.options.length=0
}
for(i=0;i<idarray.length-1;i++){
var opt=new Option();
opt.text=namearray[i];
opt.value=idarray[i]
zhandian.options.add(opt);
}
zhandian.style.display="inline"
if(address)
{
switch (address)
{
case '98108':
zhandian.selectedIndex=0
break;
case '98405':
zhandian.selectedIndex=2
break;
case '98404':
zhandian.selectedIndex=3
break;
case '98409':
zhandian.selectedIndex=4
break;
case '98407':
zhandian.selectedIndex=5
break;
case '98401':
zhandian.selectedIndex=6
break;
default:
}
}
</script>
</html>
<script language="javascript">
function seldate()
{
var MyDate,hd,md,sd,hms,index1
MyDate=showModalDialog("../Calender8.asp","","status:no;center:yes;help:no;minimize:no;maximize:no;dialogWidth:220px;dialogHeight:400px")
index1=f1.tb1.value.indexOf(" ");
hms=f1.tb1.value.substring(index1);
if((MyDate !="")&&((MyDate !=null) ))
{
f1.action="yuliangmview.asp?time=" + MyDate+" "+hms;
f1.submit()
}
}
</script>
<script language="vbscript">
function CallPreviousDay()
dim stm
stm =cdate(f1.tb1.value)-1
f1.action="yuliangmview.asp?time=" & stm
f1.submit
end function
function CallNextDay()
dim stm
stm = CDate(f1.tb1.value)+1
f1.action="yuliangmview.asp?time=" & stm
f1.submit
end function
</script>
四、总结
都是个人实战项目中的点滴积累,望有感兴趣的联系我:QQ38172679
希望多多学习!谢谢!