I have a string which is a representation of DateTime:
string dateTime = "20110801";
Now I want to use DateTime.Parse(dateTime);
It throws an Exception stating that dateTime is not in a valid format.
Can anyone tell me how it can be done??
You can use DateTime.ParseExact, which takes in the format as a parameter.
For example:
DateTime.ParseExact("20110801", "yyyyMMdd", CultureInfo.CurrentCulture)