Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validate a date
Message
From
14/07/2006 15:37:06
 
 
To
14/07/2006 15:34:12
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
ASP.NET
Miscellaneous
Thread ID:
01136539
Message ID:
01136543
Views:
20
>I have a ASP.Net webform that contains a textbox where a user should enter a date in mm/dd/yy format.
>
>How can I validate that the user enter a good date?

Try something like this:
        ' Return a date from a string value based on a date format
        ' expC1 Date
        ' expN1 Format
        ' expC2 Time
        Public Function GetDateFromString(ByVal tcDate As String, ByVal tnFormat As Integer, _
         ByVal tcTime As String) As Date
            Dim ldDate As Date
            Dim lnDay As Integer
            Dim lnMonth As Integer
            Dim lnYear As Integer
            Select Case tnFormat
                Case 1
                    lnDay = Val(Mid(tcDate, 1, 2))
                    lnMonth = Val(Mid(tcDate, 4, 2))
                    lnYear = Val(Mid(tcDate, 7, 4))
                Case 2
                    lnDay = Val(Mid(tcDate, 4, 2))
                    lnMonth = Val(Mid(tcDate, 1, 2))
                    lnYear = Val(Mid(tcDate, 7, 4))
                Case 3
                    lnDay = Val(Mid(tcDate, 9, 2))
                    lnMonth = Val(Mid(tcDate, 6, 2))
                    lnYear = Val(Mid(tcDate, 1, 4))
            End Select
            If tcTime.Length = 0 Then
                ldDate = New Date(lnYear, lnMonth, lnDay)
            Else
                ldDate = New Date(lnYear, lnMonth, lnDay, Val(Mid(tcTime, 1, 2)), Val(Mid(tcTime, 4, 2)), _
                  Val(Mid(tcTime, 7, 2)))
            End If
            Return ldDate
        End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform