Dim temp1
    Dim temp2
    temp1 = Format(Date, "m")
    temp2 = temp1 - 1
rs.Open "select * from 计量表 where 检定结论=''and 检定日期<= #" & temp1 & "#  and 检定日期>= #" & temp2 & "# ", ADOcn, adOpenKeyset, adLockOptimistic现在是错误时格式不对。
我是想对检定日期中的月和temp1和temp2中的月进行比较,这如何进行编写代码?

解决方案 »

  1.   

    dateiff 函数 数据库支持
      

  2.   

    这SQL语句怎么写了,意思是检定日期中的月份比较。
      

  3.   

    在表中的格式是2012-05-25,我现在想要4月份的数据,如何写SQL语句呢?
      

  4.   

    select * from 计量表 where 检定结论=''and datediff(Month,'2012-05-25',检测日期)=0 
      

  5.   

    Dim temp1 As Date
    Dim temp2 As Date
    Dim strDate1 As String, strDate2 As String
    Dim intYear As Integer, intMonth As Integer
    Dim strSQL As String    intYear = 2012
        intMonth = 4
        
        temp1 = DateSerial(intYear, intMonth, 1)
        temp2 = DateSerial(intYear, intMonth + 1, 1)
        strDate1 = Format(temp1, "yyyy-mm-dd")
        strDate2 = Format(temp2, "yyyy-mm-dd")
        
        strSQL = "SELECT * FROM 计量表 WHERE 检定结论=''AND 检定日期>= #" & strDate1 & "# and 检定日期< #" & strDate2 & "# "    Debug.Print strSQL----------------------------------------------------------------------------------SELECT * FROM 计量表 WHERE 检定结论=''AND 检定日期>= #2012-04-01# and 检定日期< #2012-05-01#