I have a line 20100524 (2010 05 24) and I would like to parse it as an actual date format.
DateTime.ParseExact("20100524", "yyyyMMdd", Thread.CurrentThread.CurrentCulture);
This will do it for you in a safe way:
DateTime dateTime; if (DateTime.TryParseExact("20100524", "yyyyMMdd", null, DateTimeStyles.None, out dateTime)) { // use dateTime here } else { // the string could not be parsed as a DateTime }
DateTime.Parse and Datetime.ParseExact are your friends.
DateTime result; CultureInfo provider = CultureInfo.InvariantCulture; string dateString = "20100524"; string format = "yyyyMMdd"; result = DateTime.ParseExact(dateString, format, provider);