CrBruno
CrBruno

Reputation: 1003

Date time to string conversion

I have to convert a string to date time...

String data is in this form: 13.6.2013. 8:06:36

The code:

Dim pDate As String
pDate = TextBox16.Text
Dim pro_Date As DateTime = DateTime.ParseExact(pDate, "DD.M.YYYY. hh24:mm:ss", CultureInfo.InvariantCulture)

And the error I get is: string was not recognized as a valid datetime

How to convert this?

Upvotes: 2

Views: 133

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460018

The format string is case sensitive, so this does not work: "DD.M.YYYY". Also, 24h clock is uppercase H not "hh24". You need a single H because 8:06:36 has no leading zero on the hour.

Dim pro_Date As DateTime = DateTime.ParseExact(pDate, "dd.M.yyyy. H:mm:ss", CultureInfo.InvariantCulture)

More informations acc. the "H" Custom Format Specifier

Upvotes: 2

Related Questions