Win7上的MS Excel Professional Plus v14。VBA Excel - 相等日期不等于
我在比较日期/时间的平等方面遇到问题。
看起来相等的两个日期2013/12/16 12:19:33都被标注为日期。一个是日期数组,另一个是日期变量。 arrPP稍后重新定义。当我这样做则DateDiff(“S”,DATE1,DATE2)它产生0
Dim arrPP() As Date ' During runtime shows type is Date(1 to 2, 1 to 1)
Dim dNextStartTime as Date
'...code removed ...
If arrPP(iPP_START, lPP_index) <= dNextStartTime Then
GoTo PP_OUT
End If
即使他们是平等的,上面的计算结果为假,在错误的道路取。这很难追查,并导致意外/错误的结果。
关于日期平等,有没有官方的“gotcha”?是否存在需要比较的隐藏毫秒,或将比较限制在秒级别的方法?
我已经尝试了其他几种替代方法,包括在数组元素前放置CDate。
失败:
If Not(arrPP(iPP_START, lPP_index) > dNextStartTime) Then
GoTo PP_OUT
End If
PASS:(但谁也想做到这一点?)
If arrPP(iPP_START, lPP_index) <= dNextStartTime Or _
DateDiff("s",arrPP(iPP_START,lPP_index),dNextStartTime) = 0 Then
GoTo PP_OUT
End If
'VBA Excel - 同等日期不评估为平等'你如何填充日期?这个对我有用。 –