NewtonCode
NewtonCode

Reputation: 1542

.Net 4.0 throws Invalid Date Exception

In .Net 1.1 ,the following code does not show any error.

Dim T As DateTime = "10\1\2010"

But in .Net 4.5 , the same code shows error saying "Unrecognised Date Format". Why is this happening? Why does .Net 1.1 converts "10\1\2010" to "10/1/2010" implicitly but not .Net 4.5 . Can it made possible on .Net 4.5?

Upvotes: 2

Views: 375

Answers (1)

Milan Raval
Milan Raval

Reputation: 1880

Issue is with Date seperator "\", you can use below code

        Dim culture = CultureInfo.CurrentCulture.Clone()
        culture.DateTimeFormat.DateSeparator = "\"
        Thread.CurrentThread.CurrentCulture = culture
        Thread.CurrentThread.CurrentUICulture = culture
        Dim T As DateTime = "10\1\2010"

Upvotes: 1

Related Questions