title: Show only Date in Column of DataGridView
body: <p>I have a <strong>date</strong> store in <strong>MySQL</strong> Database with the format <code>Datetime</code>.</p>
  
  <p>I want to put <strong>only</strong> the date in one <code>DataGridView</code> but when I try i get the date with the following hours, something like:</p>
  
  <pre><code>29/06/2016 12:01:21
  </code></pre>
  
  <p>I tried to find the date directly from the <strong>MySQL</strong> query using the <code>DATE()</code> function, but it still does not work because in my <code>DataGridView</code> I see the date formatted as follows:</p>
  
  <pre><code>29/06/2016 00:00:00
  </code></pre>
  
  <p>Finally I tried side code to set the column, but without result</p>
  
  <pre><code>dataGridView.Columns[1].DefaultCellStyle.Format = "dd/MM/yyyy";
  </code></pre>
  
  <p>I use <code>DataSource</code> to "link" my data to my <code>DataGridView</code>.</p>
  
  <hr>
  
  <p>This is the code:</p>
  
  <pre><code>var dataTable = listOfResult.ToDataTable(); //ToDataTable() Function that convert List into DataTable
  dataGridView.DataSource = dataTable;
  dataGridView.Columns[1].DefaultCellStyle.Format = "dd/MM/yyyy";
  </code></pre>
  
  <p>The <code>listOfResult</code> is a list of such dynamic , where inside there are all the dates.</p>
  
  <p>Function <code>ToDataTable()</code></p>
  
  <pre><code>public static DataTable ToDataTable(this IEnumerable&lt;dynamic&gt; items)
      {
          var data = items.ToArray();
          if (!data.Any()) return null;
  
          var dt = new DataTable();
          foreach (var key in ((IDictionary&lt;string, object&gt;) data[0]).Keys)
              dt.Columns.Add(key);
  
          foreach (var d in data)
              dt.Rows.Add(((IDictionary&lt;string, object&gt;) d).Values.ToArray());
  
          return dt;
      }
  </code></pre>