我无法比较日期。我的代码中的if语句表示endDate不会少,即使它是。例如,如果endDate是2/20/2017和startDate 2/22/2017 if语句说endDate不是唯一的,但它是。访问VBA比较日期不起作用
Dim startDate As Date
Dim endDate As Date
startDate = DateValue(Me.dueDateTxt)
endDate = DateValue(Me.shippedDate)
If (endDate < startDate) Then
Debug.Print "It is less"
Else
Debug.Print "not less"
End If
我也曾尝试
If Me.dueDateTxt < Me.ShippedDate Then
If CDate(startDate) < CDate(endDate) Then
If Format(startDate, "mm/dd/yyyy") < Format(endDate, "mm/dd/yyyy") Then
If DateDiff(d, startDate, endDate) > 0 Then
我失去了一些东西的地方预先感谢您的帮助!
编辑:我找出了问题所在。我有一个功能来消除假期和周末。该函数正在交换我的startDate和endDate。感谢大家的帮助和建议。
您是否尝试过国际日期,yyyy-mm-dd? – Fionnuala
我还没有尝试过。从文本框中实现的日期以mm/dd/yyyy显示。在比较它们之前,我需要更改格式吗? – Kevin
在VBA中,使用国际日期格式总是一个好主意。你可以使用FORMAT来获得这个。 – Fionnuala