In my code I need to handle two types of datetime formats. if the input date is a like 8/31/2017 12:00:00 AM I just wanna save it. But when it comes with the format like "25.11.13" I wanna convert it like this 11/25/2013 12:00:00 AM and wanna save it.
Somehow I managed my code but the problem is the "else block" is not working as expected (actually it won't work at all).
DateTime registrationDate = new DateTime();
if (DateTime.TryParse(myTable.Rows[i][6].ToString(), out registrationDate))
{
record.RegistrationDate = !string.IsNullOrEmpty(detailsTable.Rows[i][6].ToString()) ? Convert.ToDateTime(detailsTable.Rows[i][6].ToString()) : (DateTime?)null;
}
else
{
DateTime.TryParse(detailsTable.Rows[i][6].ToString(), out registrationDate);
record.RegistrationDate = registrationDate;
}