Reputation: 22966
I'm querying an SQL CE database to bind up a datasource for a datagrid to display some information.
One of the columns in the SQL CE database is a DateTime column. In the datagrid it displays the full date and time, what I'd like it to do is display the date in this format: mm/dd/yyyy
How can I go about doing this?
Upvotes: 1
Views: 709
Reputation: 10644
If you know which column has date you could modify property of cell style for column:
System.Windows.Forms.DataGridViewCellStyle dgvCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
dgvCellStyle1.Format = "MM/dd/yyyy";
dgvCellStyle1.NullValue = null;
this.dataGridView1.Columns[0].DefaultCellStyle = dgvCellStyle1;
Upvotes: 2
Reputation: 2742
Use can modify your query and use convert function to display date in desired format
convert(varchar(10), datetimefieldname, 103)
Another approach could be following, although I wouldn't prefer it much
cast(month(logindatetime) as varchar(2)) + '/' + cast(day(logindatetime) as varchar(2)) + '/' + cast(year(logindatetime) as varchar(4))
Upvotes: 1