Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validate A Date Entry
Message
 
To
19/11/2001 23:48:58
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00583203
Message ID:
00583826
Views:
29
>>>How is it possible to validate a date type textbox.
>>>
>>>the date format I'm using is DD/MM/YY
>>>
>>>I tried using ISDATE("30/02/2001"), it returns true.
>>>I tried using ISDATE("02/13/2001"), it returns true.
>>>
>>>Am I missing something here.
>>
>>
>>Better use the Date Time Picker control. If you use a textbox, you will need to check everything yourself.
>
>I'm validating it in a grid.

In this case you can use something like this:
Option Explicit

Private Sub Command1_Click()
'To convert from DD/MM/YY
Dim intDay As Integer
Dim intMonth As Integer
Dim intYear As Integer
Dim strDate As String
    
    strDate = "20/11/01"
    intDay = Left$(strDate, 2)
    intMonth = Mid$(strDate, 4, 2)
    intYear = Right$(strDate, 2)
    intYear = intYear + IIf(intYear < 50, 2000, 1900)
    If Format$(DateSerial(intYear, intMonth, intDay), "DD/MM/YY") = strDate Then
        MsgBox "Date " & strDate & " is valid"
    Else
        MsgBox "Date " & strDate & " is not valid"
    End If

    strDate = "30/02/01"
    intDay = Left$(strDate, 2)
    intMonth = Mid$(strDate, 4, 2)
    intYear = Right$(strDate, 2)
    intYear = intYear + IIf(intYear < 50, 2000, 1900)
    If Format$(DateSerial(intYear, intMonth, intDay), "DD/MM/YY") = strDate Then
        MsgBox "Date " & strDate & " is valid"
    Else
        MsgBox "Date " & strDate & " is not valid"
    End If


    strDate = "02/13/01"
    intDay = Left$(strDate, 2)
    intMonth = Mid$(strDate, 4, 2)
    intYear = Right$(strDate, 2)
    intYear = intYear + IIf(intYear < 50, 2000, 1900)
    If Format$(DateSerial(intYear, intMonth, intDay), "DD/MM/YY") = strDate Then
        MsgBox "Date " & strDate & " is valid"
    Else
        MsgBox "Date " & strDate & " is not valid"
    End If
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Reply
Map
View

Click here to load this message in the networking platform