>you should compare date values as dates, which means using DateDiff
Sure it's possible to use the DateDiff() function.
But, I beleive it's not needed if just comparing dates, when the dates are in, or converted to, Date types.
Dim Date1 As Date
Dim Date2 As Date
Date1 = #somedate# 'Or = CDate(SomeDateString)
Date2 = #somedate#'Or = CDate(SomeDateString)
If = Date1 <> Date2 Then
Which is much much of faster than the DateDiff().
Or
Dim Date1 As String
Dim Date2 As String
Date1 = SomeDateString
Date2 = SomeDateString
If = CDate(Date1) <> CDate(Date2) Then
Both of these examples will compare the dates, AND are much more efficient than using the Format$() or DateDiff() functions. Especially in a long loop you will see the difference in speed.
When comparing something other than the Dates/Days themselves, such as years, then using the Year(), Month() functions are still more efficient than the Format or DateDiff functions.
IF one date variable contains a Date (actually midnight of a certain date), and the other DateTime (other than midnight), then the comparison will not be equal unless you use the DateValue() function on the one containtin the DateTime:
Dim Date1 As String
Dim Date2 As String
Date1 = SomeDateString
Date2 = SomeDateString
If DateValue(date1) = DateValue(date2) Then
This is still faster than the DateDiff()
The primary purpose of the DateDiff() function is not to do a boolean comparison, but to return the actual Difference between two dates.
The original question was to compare:
date1>date2
and not to get the actual difference.