title: How to convert string To DateTime in C#
body: <p>I am getting this error:</p>
  
  <blockquote>
    <p>An exception of type 'System.FormatException' occurred in mscorlib.dll
    but was not handled in user code</p>
    
    <p>Additional information: String was not recognized as a valid DateTime.</p>
  </blockquote>
  
  <p>My two classes are shown here:</p>
  
  <pre><code>public class GigFormViewModel
  {
      public string Venue { get; set; }
      public string Date { get; set; }
      public string Time { get; set; }
      public byte Genre { get; set; }
  
      public IEnumerable&lt;Genre&gt; Genres { get; set; }
  
      public DateTime DateTime
      {
          get { return DateTime.Parse(string.Format("{0} {1}", Date, Time)); }
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class Gig
  {
      public int Id { get; set; }
  
      [Required]
      public ApplicationUser Artist { get; set; }
  
      [Required]
      public string ArtistId { get; set; }
  
      public DateTime DateTime { get; set; }
  
      [Required]
      [StringLength(255)]
      public string Venue { get; set; }
  
      public Genre Genre { get; set; }
  
      [Required]
      public byte GenreId { get; set; }
  }
  </code></pre>