user279521
user279521

Reputation: 4807

Trying to convert a string to date time format in vb.net 2005

I can't seem to be able to convert a string that contains date value of "100714 0700" (2010-07-14 7am) to a date format in vb.net 2005

When I attempt to do:

        Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
        strPickupDateTime = DateTime.ParseExact(txtPickupDate.Text, "yymmdd", provider)  

I get back "1/14/2010 12:07:00 AM"
How can I get a value of "2010-07-14 7:00" ?

Upvotes: 2

Views: 3189

Answers (2)

wageoghe
wageoghe

Reputation: 27608

Here is another link from here on SO that shows how to do this in C#

Convert String to Date in .NET if my incoming date format is in YYYYMMDD

In your case you probably also want add the time format:

  string s = "100714 0700";
  DateTime d = DateTime.ParseExact(s, "yyMMdd hhmm", CultureInfo.InvariantCulture);

Upvotes: 3

MyHeadHurts
MyHeadHurts

Reputation: 1562

Sorry, I read the question to quickly last time, hmmm have you tried something like strPickupDateTime = DateTime.ParseExact(txtPickupDate.Text, "yy" & "-" & "-" & "mm" & "-" & "dd", provider)

Upvotes: 0

Related Questions