title: String was not recognized as valid date time c# error
body: <p>I have below code which is converting many other string formats in a valid datetime format.</p>
  
  <pre><code>  try
    {
    outputDate = DateTime.Parse(inputDateTime);
    }
    catch
    {
    outputDate = DateTime.Parse(inputDateTime, new CultureInfo("en-US"));
    }
  </code></pre>
  
  <p>However for below two cases it always failing</p>
  
  <p>GetValidDateTimeFromString error for <strong>13-10-2018 05:00:27</strong>-> String was not recognized as a valid DateTime.   at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
     at O365InventoryApp.InventoryDataUtility.GetValidDateTimeFromString(String inputDateTime, TextWriter log)</p>
  
  <p>GetValidDateTimeFromString error for <strong>14-10-2018 00:57:21</strong>-> String was not recognized as a valid DateTime.   at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
     at O365InventoryApp.InventoryDataUtility.GetValidDateTimeFromString(String inputDateTime, TextWriter log)</p>
  
  <p>Note the highlighted two dates which are throwing exception while converting.I think it's a 24 hour format problem.So I also tried to convert like below</p>
  
  <pre><code>log.WriteLine("GetValidDateTimeFromString error for " + inputDateTime + "-&gt; " + ex.Message + ex.StackTrace);
                      CultureInfo provider = CultureInfo.InvariantCulture;
                      DateTimeStyles style = DateTimeStyles.None;
                      string[] format = new string[] { "dd-MM-yyyy h:m:s tt", "dd-MM-yyyy hh:mm:ss tt" };
  
                      DateTime dt;
                      if (DateTime.TryParseExact(inputDateTime, format, provider, style, out dt))
                      {
                          log.WriteLine("updated date -" + dt);
                          outputDate = dt;
                      }
  </code></pre>
  
  <p>Anyone can enlighten me what's happening here?</p>