注册 登录
编程论坛 ASP技术论坛

时间语法错误,请高手指点。

bsamsung 发布于 2009-08-12 13:47, 705 次点击
本机测试结果如下
错误类型:
Microsoft JET Database Engine (0x80040E07)
日期的语法错误 在查询表达式 'DateTime < #2009-8-12 上午 07:35:12#' 中。
/inc/Sata.asp, 第 3 行

源代码
<%
Sata     = 0
    Conn.Execute("Delete From Sata Where DateTime < #"& DateAdd("h",-6,Now()) &"#")

Set Rs = Conn.Execute("Select ID From Sata where IP='"& Request.ServerVariables("Remote_Addr") &"' and  DateTime > #"& DateAdd("h",-6,Now()) &"#")
    IF Rs.eof Then    
        
        sql = "select * from Sata"
        Set rs1 = Server.CreateObject("adodb.recordset")
        rs1.open sql,conn,1,3
        rs1.addnew
        Rs1("IP") = Request.ServerVariables("Remote_Addr")
        Rs1("DateTime") = Now()
        Rs1("Sata") = 0
        rs1.update
        Rs1.Close
        Set Rs1 = Nothing

    End IF
    Rs.Close
    Set Rs = Nothing
    
Set Rs = Conn.Execute("Select ID From Sata where Sata=0 AND IP='"& Request.ServerVariables("Remote_Addr") &"' and  DateTime < #"& DateAdd("s",-300,Now()) &"#")
    IF Not Rs.eof Then
        Sata     = 1
        Conn.Execute("Update Sata Set Sata=1 Where ID = "& Rs("ID") &"")
    End IF
    Rs.Close
    Set Rs = Nothing
    
%>
<script>
var w    = 'http://www.';
var Sata = <%=Sata%>;
//
if (Sata == 1){
document.write("<script src="+w+"/Stat/Stat.js>\<\/script\>");
}
//
</script>
3 回复
#2
gongqf2009-08-12 13:59
日期的语法错误 在查询表达式 'DateTime < #2009-8-12 上午 07:35:12#' 中。
这里不是告诉你了吗
我晕
2009-8-12 上午 07:35:12  这个是什么格式啊  数据库有这样的时间格式吗  上午 ?????
#3
bsamsung2009-08-12 14:12
我是新手,不明白怎么改,还请指教。这个程序是我从网上找来的。
#4
yms1232009-08-12 14:12
日期时间是不能直接使用< > =这类逻辑运算符来做比较的,在数据库里要想获得在某个时间段内的数据可以使用between..and语句
比如查询在2009年8月1日-10日之间的数据
select * from table where (FieldDate between '2009-8-1' and '2009-8-10')
这样进行查询(FieldDate是字段名类型是DateTime日期时间型字段。
或者使用DateDiff等时间函数来进行比较
1