How to convert String to date
<p>I have a requirement to treat strings of the form 20031006, among others as datetime. Using the C# functions, I came up with the function below for converting most all of my dates in my application. However, I don't seem to have the format for converting the string 20031006 to date. What methods do I use to accomplish this please? Thanks in advance. </p>

<pre><code> private bool IsDate(string dateString)
        {
            string format;
            DateTime dateValue;
            CultureInfo enUS = new CultureInfo("en-US"); 
            CultureInfo provider = CultureInfo.InvariantCulture;
            DateTime myNum;
            try
            {
                if (DateTime.TryParse(dateString, out myNum))
                {
                    return true;
                }
                format = "d";
                if (DateTime.TryParseExact(dateString, "d",provider, DateTimeStyles.AdjustToUniversal, out dateValue))
                {
                    return true;
                }

                dateValue = DateTime.ParseExact(dateString, format, new CultureInfo("fr-FR"));
                if (dateValue != null)
                {
                    return true;
                }
                if (DateTime.TryParseExact(dateString, "g", enUS, DateTimeStyles.None, out dateValue))
                {
                    return true;
                }

                if (DateTime.TryParseExact(dateString, "M/dd/yyyy hh:mm", enUS, DateTimeStyles.None, out dateValue))
                {
                    return true;
                }
                if (DateTime.TryParseExact(dateString, "g", enUS, DateTimeStyles.AllowLeadingWhite, out dateValue))
                {
                    return true;
                }
                if (DateTime.TryParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue))
                {
                    return true;
                }
                if (DateTime.TryParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.AdjustToUniversal, out dateValue))
                {
                    return true;
                }
                if (DateTime.TryParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dateValue))
                {
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }

            return false;
        }
</code></pre>
