You have to use
DateTime.TryParseExact
if you are using custom date time format.
First,
using System.Globalization;
DateTimeFormatInfo dateFormat = new DateTimeFormatInfo();
dateFormat.DateSeparator = "/";
string input1 = "18/10/2012";
string input2 = "17/10/2012";
DateTime date1 = DateTime.MinValue;
DateTime date2 = DateTime.MinValue;
if (DateTime.TryParseExact(input1, "dd/MM/yyyy", dateFormat, DateTimeStyles.AllowWhiteSpaces, out date1))
{
}
else
{
throw new Exception("Input 1 is not a valid recognised date");
}
if (DateTime.TryParseExact(input2, "dd/MM/yyyy", dateFormat, DateTimeStyles.AllowWhiteSpaces, out date2))
{
}
else
{
throw new Exception("Input 2 is not a valid recognised date");
}
if (date1 > date2)
{
}
else
{
}