Reputation: 5355
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??
Upvotes: 2
Views: 152
Reputation: 900
You can use DateTime.ParseExact, which takes in the format as a parameter.
For example:
DateTime.ParseExact("20110801", "yyyyMMdd", CultureInfo.CurrentCulture)
Upvotes: 3