Try this
private static string FormatDate(string sDate)
{
// "6/16/1989"
//mysql format 06-16-1989
DateTime date;
if (!DateTime.TryParseExact(sDate, new string[] { "MM/dd/yyyy", "M/dd/yyyy", "MM/d/yyyy" }, System.Globalization.CultureInfo.CurrentCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out date))
{
return string.Empty;
}
return date.ToString("MM-dd-yyyy");
}
This would also work if you just wanted to use a standard TryParse:
private static string FormatDate(string sDate)
{
// "6/16/1989"
//mysql format 06-16-1989
var usCultureInfo = System.Globalization.CultureInfo.GetCultureInfo(0x0409);
DateTime date;
if (!DateTime.TryParse(sDate, usCultureInfo, System.Globalization.DateTimeStyles.AdjustToUniversal, out date))
{
return string.Empty;
}
return date.ToString("MM-dd-yyyy");
}
Note that these examples will return an empty string when the date isn't understood.
But do consider using the MySQL driver and parameterized queries since this will make your code safer and it will be easier to work with.