I am converting strings to DateTime and have the strings coming in like this:
string dateTimeBeforeDayTen = '2/05/2016';
string dateTimeBeforeAfterTen = '12/05/2016';
Now if I am parsing the dateTimeBeforeAfterTen, I know I can use:
DateTime myDateTime;
DateTime.TryParseExact(dateTimeBeforeAfterTen, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out myDateTime);
But what do I do if I want to parse for either of them. I know I could do:
DateTime myDateTime;
if(!DateTime.TryParseExact(dateTimeBeforeAfterTen, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out myDateTime));
DateTime.TryParseExact(dateTimeBeforeAfterTen, "d/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out myDateTime);
But is there a better way to do this? I am storing the DateTime format in the DB and would like to keep it as a single string.