是SQL Server吗?
如果是,建议改成这样~~
'转换日期格式为SQL能接受的格式(月/日/年 时:分:秒)
Public Function GetSQLTimeFormat(ByVal d As Date) As String
    
    GetSQLTimeFormat = "'" & DatePart("yyyy", d) & "-" & DatePart("m", d) & "-" & DatePart("d", d) & " " & Format(d, "HH:nn:ss") & "'"
    
End FunctionDim rstemp As New ADODB.Recordset
'Set rstemp = New ADODB.Recordset
Dim StartTime As Date
Dim EndTime As Date
Dim strSQl As String
StartTime = 2002 - 1 - 1
EndTime = 2002 - 12 - 31
strSQl = "select * from present where 日期 between " & GetSQLTimeFormat(StartTime) & " and " & GetSQLTimeFormat(EndTime)
rstemp.Open strSQl, gadoConnect, 1, 3
Call ShowData(rstemp)

解决方案 »

  1.   

    试试这样:
    Access数据库:
    rstemp.Open "select * from present where 日期 between #2002-1-1# and #2002-12-31#", conn, 1, 3SQL Server数据库:
    rstemp.Open "select * from present where 日期 between '2002-1-1' and '2002-12-31'", conn, 1, 3
      

  2.   

    OR 
    StartTime = #1/1/2002#
    EndTime = #12/31/2002#
      

  3.   

    呵呵,其实我写的就是hycao(海草)里的写法,只不过是想考虑通用一下~~
    '转换日期格式为SQL能接受的格式(月/日/年 时:分:秒)
    Public Function GetSQLTimeFormat(ByVal d As Date) As String
        
        GetSQLTimeFormat = "'" & DatePart("yyyy", d) & "-" & DatePart("m", d) & "-" & DatePart("d", d)     
    End FunctionDim rstemp As New ADODB.Recordset
    'Set rstemp = New ADODB.Recordset
    Dim StartTime As Date
    Dim EndTime As Date
    Dim strSQl As String
    StartTime = 2002 - 1 - 1
    EndTime = 2002 - 12 - 31
    strSQl = "select * from present where 日期 between " & GetSQLTimeFormat(StartTime) & " and " & GetSQLTimeFormat(EndTime)
    rstemp.Open strSQl, gadoConnect, 1, 3
    Call ShowData(rstemp)如果这样,运行的结果就是rstemp.Open "select * from present where 日期 between '2002-1-1' and '2002-12-31'", conn, 1, 3