title: Format DateTime in MVC4 via Properties
body: <p>I have created a class that maps to my database model. One of the properties is StartDate</p>
  
  <p><code>public DateTime? StartDate { get; set; }</code></p>
  
  <p>I can easily grab this while building my model and place it in my view.</p>
  
  <p>What I would like to do is have the view show a more friendly date MM/dd/yyyy.  I'm aware of the <code>.ToString(MM/dd/yyyy)</code> and have attempted to use properties to set it.  I'm having troubles because the database is set as a nullable DateTime and I'd like to return a string.  Maybe I'm not using the correct approach</p>
  
  <p>Code to retrieve from db</p>
  
  <pre><code>var newsItem = (from n in context.News
                      where n.NewsID == id
                      select new Models.Components.NewsModel
                      {
                          NewsId = n.NewsID,
                          Header = n.Header,
                          MainPhoto = n.MainImage,
                          Text = n.Text,
                          Date = n.CreatedDate,
                          Active = n.Active,
                          StartDate = n.StartDate,                                                                
                          EndDate = n.EndDate
                      }).FirstOrDefault();
  </code></pre>
  
  <p>Trying to set the value</p>
  
  <pre><code>private DateTime? _StartDate { get; set; }
  public string StartDate
  {
      get
      {
          DateTime tmp;
          DateTime.TryParse(_StartDate.ToString(), out tmp);
          return tmp.ToString("MM/dd/yyyy");
      }
      set { _StartDate = value; }
  }
  </code></pre>
  
  <p>This complains because _StartDate is a DateTime? value</p>
  
  <p>What is the most efficient way to display the date in the format I specified?</p>