Akhil K Nambiar
Akhil K Nambiar

Reputation: 3975

Date time format convert in vb.net

I'm getting date-time from a source as 20110731183330. I want to convert it to '7/31/2011 06:33:30 PM'. Is there a one line code for the same in vb.net?

Upvotes: 1

Views: 20373

Answers (3)

Akhil K Nambiar
Akhil K Nambiar

Reputation: 3975

Dim result As Date = Date.ParseExact(dt, "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture)

then we can format it as required.

Upvotes: 0

Wahid4sap
Wahid4sap

Reputation: 227

It can be...

Dim CustomDate As Date = Date.ParseExact(yourdate, "MM/dd/yyyy hh:mm:ss tt", Globalization.DateTimeStyles.None)

Upvotes: 0

drf
drf

Reputation: 8699

That would be:

Dim result As Date = Date.ParseExact(datestring, "yyyyMMddHHmmss")

Upvotes: 4

Related Questions