title: Setting DateTime display format at runtime with MVC3
body: <p>I'm rendering an input control which holds a DateTime value:</p>
  
  <pre><code>[DataType(DataType.Date)]
  public DateTime? ScheduledDateTime { get; set; }
  </code></pre>
  
  <p>The formatting applied to the input is stored as a user preference which is retrieved from the database at runtime.</p>
  
  <p>So, I've got the following value at run-time: </p>
  
  <blockquote>
    <p>YYYY-MM-DD</p>
  </blockquote>
  
  <p>The actual formatting not-withstanding, how can I tell my model binder to format the DateTime as specified? All examples I've found rely on setting the DateFormatString attribute, but this is only able to be set with a compile time constant. This makes it unusable for my purposes.</p>
  
  <p>Something with override the default model binder? Anyone got an example, I haven't been able to turn one up Googling.</p>
  
  <p>EDIT: Maybe I create a new HtmlHelper which will handle the conversion at runtime?</p>
  
  <p>EDIT2: Pretty sure I'm going to go about it like this. Pardon the overly verbose naming convention:</p>
  
  <pre><code>&lt;%= Html.TextBoxFor(model =&gt; model.ScheduledDateTime, string.Format("{0:" + User.GetDateFormatStringAsCSharpFormat(SessionManager.Default.User.DateFormat)+ "}", Model.ScheduledDateTime))%&gt;
  </code></pre>