StevieB
StevieB

Reputation: 6541

ASP.NET how to convert string to Date without forward slashes

Just wondering how I can convert the following string into a datetime 111222, at the moment it is telling me that this is not a valid datetime value..

Upvotes: 0

Views: 1560

Answers (1)

keyboardP
keyboardP

Reputation: 69372

You can use the DateTime.ParseExact method and supply the format your input is in.

Edit - added code:

  DateTime dt = DateTime.ParseExact("111222", "yyMMdd", CultureInfo.InvariantCulture);
  Console.WriteLine(dt.ToString());

Upvotes: 3

Related Questions