title: DateTime.TryParse or Datetime.TryParseExact?
body: <p>I am converting date and time from a string. I append the date parts from my input like below</p>
  
  <pre><code>string joinedString = txtMonth.Text.Trim() + "/" + txtDate.Text.Trim() + "/" + txtYear.Text.Trim();
  </code></pre>
  
  <p>Generally i convert the string like below</p>
  
  <pre><code>DateTime dt;
  if (DateTime.TryParse(joinedString, out dt))
  {
      lblOutputCulture.Text = dt.ToString();
  }
  else
  {
      lblOutputCulture.Text = "Invalid Date Time!!!";
  }
  </code></pre>
  
  <p>Here i can get the datetime if the culture and datetime format of the culture is same as my string pattern. But if it is chnaged like 'dd-MM-yy' the conversion shoul failed.</p>
  
  <p>To overcome this, we need to parse using InvariantCulture. For this i found 2 methods </p>
  
  <p>Method 1 : Using DateTime.TryParse</p>
  
  <pre><code>if (DateTime.TryParse(joinedString, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
  {
      lblOutput.Text = dt.ToString();
  }
  else
  {
      lblOutput.Text = "Invalid Date Time!!!";
  }
  </code></pre>
  
  <p>Here the date time is successfully converted even if the datetime format of the system is changed. Also the following advatages
   i) The date and month input is 1 digit or 2 digit
   ii) The year input is 2 digit or 4 digit </p>
  
  <p>Method 2: Using DateTime.TryParseExact</p>
  
  <pre><code>if (DateTime.TryParseExact(joinedString, "M/d/yy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
  {
      lblOutput.Text = dt.ToString();
  }
  else
  {
      lblOutput.Text = "Invalid Date Time!!!";
  }
  </code></pre>
  
  <p>Here also datetime is converted with out culture specific but strict to the format i gave in the tryparseexact statement.</p>
  
  <p>But the following are the issues for this
   i) If i gave 4 digit year input it shows invalid date and time. If i change the format to 'M/d/yyyy' i can't able to give 2 digit year number. Like if i add time part, i need to give time part mandatory.</p>
  
  <p>So which one is better? Please give a suggestion. But mostly i found the second method in all blogs and forums..</p>
  
  <p>Which one is correct?</p>