Rod,
I would use the Split function. Check the upper bound of the resulting array
to see if 3 parts were returned. If not, then you can assume that a
different delimiter was used. (Code below is not tested).
Dim DateArray
DateArray = Split(MyDate,"/")
If UBound(DateArray) < 2 Then
' The date does not contain / characters
* Put code here to check for other formats or cause error
Else
' The date DOES have / characters. Confirm valid format.
If DateArray(2) = 0 Then DateArray(2) = 2000
* Put other validation code here
End If
What do you mean by "European format"? If you mean this:
US format = mm/dd/yyyy
European format = dd/mm/yyyyy
...then it will be difficult to check for certain. If you mean this:
European format = dd-mm-yyyyy
... then modify the above code as follows:
Dim DateArray
DateArray = Split(MyDate,"/")
If UBound(DateArray) < 2 Then
' The date does not contain / characters
' Check for European format
DateArray = Split(MyDate,"-")
If UBound(DateArray) < 2 Then
' Date does not contain - charcters either. Error
* Put error handling code here
Else
' Date is European/military format. Check validity
If DateArray(2) = 0 Then DateArray(2) = 2000
* Put other validation code here
End If
Else
' The date DOES have / characters. Confirm valid format.
If DateArray(2) = 0 Then DateArray(2) = 2000
* Put other validation code here
End If
I hope this gives you a start.
Charlie
Quote:
> I'm trying to read in and validate a date field such as 05/06/2000, and I
> want to make sure that "/"'s exist in the correct position and check to
see
> if the year is 2000 and not 00. Can someone please give me a head start.
> Any idea on how to make sure the date is in either an American or European
> format?
> Thanks,
> Rod