Date Formatting

  • Thread starter Thread starter S. S.
  • Start date Start date
S

S. S.

Is there a way to specify that a Date format can only be
in MM-DD-YY, not MM/DD/YY?

If Answer = "" Then Exit Sub
If Not IsDate(Answer) Then
MsgBox "Invalid Date!"
Exit Sub
End If

This will confirm that it is a date, but won't distinguish
between / and -.

Thanks

S.
 
Maybe something like this?

Sub Test()

Dim Answer As String

Answer = Trim(InputBox("Enter date in DD-MM-YY format"))
If Answer = "" Then Exit Sub
If Not IsDate(Answer) Then
MsgBox "Invalid Date!"
Exit Sub
End If
If Mid(Answer, 3, 1) <> "-" Or _
Mid(Answer, 6, 1) <> "-" Or Len(Answer) <> 8 Then
MsgBox "You must use 2 digits for day, month and year" _
& " and you must use hyphen (-) as the separator"
Exit Sub
End If

End Sub
 
Back
Top