Hi, How to convert the string "28/09/2009" to DateTime in an specific format? Ex: I want to convert "2009-09-28 17:30:40" to DateTime. I want to convert "28/09/2009 17:30:40" to DateTime. I want to convert "20090928 17:30:40" to DateTime.
There is multiples possible formats. I try this:
string[] formats = new string[] {"yyyymmdd","yyyymmddThhmmss","yyyy/mm/dd hh:mm:ss","yyyy/mm/dd","yyyy-mm-dd hh:mm:ss","yyyy-mm-dd"};
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime formattedDate = DateTime.ParseExact(aDate, formats, culture, DateTimeStyles.None);
These example throws an exception with the message "String was not recognized as a valid DateTime".
What's wrong in the code above?