1. You have to check that the datetime string is a valid one using TryParse method;
2. If it is a valid datetime string, then do the conversion to datetime else abort.
using System;
public class Program
{
public static void Main()
{
string dateString = "27/04/2014 00:00:00 AM";
Console.WriteLine("The original string is {0}", dateString);
DateTime dt;
if (DateTime.TryParse(dateString, out dt))
{
string format = "yyyy-MM-dd";
Console.WriteLine(dt.ToString(format));
}
else
{
Console.WriteLine("Not a valid datetime");
}
}
}