Is there a way to Parse String to DateTime, when the string comes with different formats : <p>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:-</p>

<pre><code>03/30/2016 10:55:49
04/01/2016 11:02
</code></pre>

<p>now when i try to parse the above string into a date-time as follow:-</p>

<pre><code>formattedDateCreated = DateTime.ParseExact(fields[DateCreatedIndex], "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
</code></pre>

<p>i will get the following exception when i try to parse the second date :-</p>

<pre><code>String was not recognized as a valid DateTime
</code></pre>

<p>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</p>
