title: Change DateTime format when using Entity Framework
body: <p>How to change the <code>DateTime</code> format when using Entity Framework?</p>
  
  <p>In my database table, the column <code>sb_ActivityDate</code> is of 'datetime' datatype.</p>
  
  <p><a href="https://i.stack.imgur.com/J3RD4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J3RD4.png" alt="enter image description here"></a></p>
  
  <p>Here is how I get that column's value:</p>
  
  <pre><code>var query = context.CPDActivities.AsQueryable();
  
  if (!(member.MemberID == Guid.Empty))
  {
      query = query.Where(e =&gt; e.sb_MemberContactId == member.MemberID).OrderBy(e=&gt;e.sb_ActivityDate).ThenBy(e =&gt; e.CreatedOn);
  } 
  else
  {
      return null;
  }
  </code></pre>
  
  <p>And stepping through the code can see that the 'sb_ActivityDate' value is now in M/d/yyyy format where I need dd/MM/yyyy.</p>
  
  <p><a href="https://i.stack.imgur.com/hAYA1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hAYA1.png" alt="enter image description here"></a></p>
  
  <p>The property for the date created by Entity Framework database first:</p>
  
  <pre><code>        public Nullable&lt;System.DateTime&gt; sb_ActivityDate { get; set; }
  </code></pre>
  
  <p>Edit 1: my system date format:</p>
  
  <p><a href="https://i.stack.imgur.com/e6bsj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e6bsj.png" alt="enter image description here"></a></p>
  
  <p>Edit 2:</p>
  
  <ul>
  <li>Visual Studio 2017</li>
  <li>.Net version 4.5.1</li>
  </ul>
  
  <p>Edit 3:</p>
  
  <p><a href="https://i.stack.imgur.com/Ee2va.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ee2va.png" alt="enter image description here"></a></p>
  
  <p>Edit 4:</p>
  
  <p>Added a simple test textbox with date:</p>
  
  <pre><code>tb_dateTest.Text = DateTime.Now.ToString();
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SPV9L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SPV9L.png" alt="enter image description here"></a></p>
  
  <p>This seems to show the CMS culture is not causing the issue.  Something else is formatting the date.</p>