I am working on building a console application which read a .csv file and add the values to the database. now i have some CSV columns which store date time values. But those column sometimes contain the datatime with seconds while sometimes it does not. here is a sample of some data for the date field:-
03/30/2016 10:55:49
04/01/2016 11:02
now when i try to parse the above string into a date-time as follow:-
formattedDateCreated = DateTime.ParseExact(fields[DateCreatedIndex], "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
i will get the following exception when i try to parse the second date :-
String was not recognized as a valid DateTime
so can anyone advice on this please? how i can make my Parse more dynamic to work on date formats with seconds or without seconds?? Thanks