DateTime.ParseExact(..)

P

Pablo

Hello,

I have big problem with method ParseExact from class DateTime.
Here is code sample:

'-----------------------------------------------------------------------------------------------------------------------------------------
Module Module1
Sub Main()
Console.WriteLine("Start...")
Try
Dim dt_ok As DateTime = New DateTime(1899, 12, 29, 0, 0, 0)
Dim dt_exception As DateTime = New DateTime(1899, 12, 30,
0, 0, 1)

Dim str_ok As String = dt_ok.ParseExact(dt_ok,
"yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)
Console.WriteLine("OK: " + str_ok)

Dim str_exception As String =
dt_exception.ParseExact(dt_exception, "yyyy-MM-dd",
System.Globalization.CultureInfo.InvariantCulture)
Console.WriteLine("OK: " + str_exception)

Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.WriteLine("Press ENTER for exit...")
Console.ReadLine()
End Sub
End Module
'-----------------------------------------------------------------------------------------------------------------------------------------

For date 1899/12/29(or 31) ParseExact works fine but for date
1899/12/30 i have exception:
String was not recognized as a valid DateTime. (thrown by ParseExact )

I have read about structure DateTime and i know that this time is
special but i don't understand why it dosn't want to work :/

Tkank you for all aswears.

regard
Pawel Modrzejewski
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top