title: DateTime.TryParse century control C#
body: <p>The result of the following snippet is "12/06/1930 12:00:00". How do I control the implied century so that "12 Jun 30" becomes 2030 instead? </p>
  
  <pre><code>    string dateString = "12 Jun 30"; //from user input
      DateTime result;
      DateTime.TryParse(dateString, new System.Globalization.CultureInfo("en-GB"),System.Globalization.DateTimeStyles.None,out result);
      Console.WriteLine(result.ToString());
  </code></pre>
  
  <p>Please set aside, for the moment, the fact that a <em>correct</em> solution is to specify the date correctly in the first place.</p>
  
  <p>Note: The result is independant of the system datetime for the pc running the code.</p>
  
  <p>Answer: Thanks Deeksy</p>
  
  <pre><code>    for (int i = 0; i &lt;= 9; i++)
      {
          string dateString = "12 Jun " + ((int)i * 10).ToString();
          Console.WriteLine("Parsing " + dateString);
          DateTime result;
          System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-GB");
          cultureInfo.Calendar.TwoDigitYearMax = 2099;
          DateTime.TryParse(dateString, cultureInfo , System.Globalization.DateTimeStyles.None, out result);
          Console.WriteLine(result.ToString());
      }
  </code></pre>