Question: I want to convert a string which contains the date in `yyyyMMdd` format to `mm-dd-yyyy` DateTime format. How do I get it?

Answer: 
```
var dateString = "20050802";
var date = myDate = DateTime.ParseExact(dateString,
                                    "yyyyMMdd",
                                    System.Globalization.CultureInfo.InvariantCulture);

```
```
public static DateTime ConvertDate(string date, string pattern)
{
    DateTime retval = DateTime.MinValue;
    if (System.DateTime.TryParseExact(date, pattern, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None, out retval))
       return retval;

    // Could not convert date..
    return DateTime.MinValue;
}

DateTime myDate = ConvertDate("20101230", "yyyyMMdd");

```