Wizzarding
Wizzarding

Reputation: 81

Problem with DateTime.TryParseExact

Could someone tell me what is wrong with this code please.

Public Shared Function TestDateTime() As String
    Dim Result As String = ""

    Dim Test As DateTime
    If DateTime.TryParseExact("20110331_153103", "yyyyMMdd_hhmmss", Globalization.CultureInfo.InvariantCulture, Globalization.DateTimeStyles.None, Test) Then
        Result = "Valid DateTime"

    Else
        Result = "Not a valid DateTime"

    End If

    Return Result
End Function

I'm sure it should return "Valid DateTime" but it will not whatever parameters I pass for the culture and datetimestyle

Thanks.

Upvotes: 0

Views: 4027

Answers (1)

Anton Gogolev
Anton Gogolev

Reputation: 115809

For starters, try `..._HHmmss'.

Upvotes: 4

Related Questions