I played around a bit, and found this 'solution'. I search the string for a "/" character before trying to cdate it. It gets rid of nearly all of the non-dates before I use cdate to convert. In my mind, the fact that this works says that microsoft's function is less than optimal. I would think it would kick out anything that is obviously not a date very quickly. For those curious, here is the new code snippet
For intCounter = 1 To 100000
On Error Resume Nex
dte1 = #1/1/1900
dte2 = #1/1/1900
If InStr(str1, "/", CompareMethod.Text) > 1 The
dte1 = CDate(str1
End I
If InStr(str2, "/", CompareMethod.Text) > 1 The
dte2 = CDate(str2
End I
[Date].Compare(dte1, dte2
Nex
Note that I increased the loop by a factor of 1,000, and it now takes 1.1 seconds regardless of whether str1 is not a date, str2 is not a date, or both. Without the 'pre-check', this would have about 4 hours and 15 minutes :
Eric
|