Convert unusual string into date time

Posted by BlueChippy on Stack Overflow See other posts from Stack Overflow or by BlueChippy
Published on 2011-08-25T08:49:24Z Indexed on 2012/12/11 23:04 UTC
Read the original article Hit count: 154

Filed under:
|
|

I have a system that outputs dates in the format "1{yy}{MM}{dd}" and I am trying to find a good way to parse it back into a real date. At the moment I am using this:

  var value = "1110825";
  var z = Enumerable.Range(1,3).Select(i => int.Parse(value.Substring(i, 2))).ToList();
  var d = new DateTime(2000 + z[0], z[1], z[2]);

but I'm sure there's a cleaner/more efficient way to do it?

I've tried DT.ParseExact, but can't find a suitable format string to use.

© Stack Overflow or respective owner

Related posts about c#

Related posts about string