日期的比较,DTPicker的格式比较月份
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中的月进行比较,这如何进行编写代码?
[解决办法]
select * from 计量表 where 检定结论=''and datediff(Month,'2012-05-25',检测日期)=0
[解决办法]
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#