I have this code showing the data in my datagridview but I want to change the format of date and time how do I change the format of DateTime?
Datagrid.Columns.Add("datetime",typeof(DateTime));
I have this code showing the data in my datagridview but I want to change the format of date and time how do I change the format of DateTime?
Datagrid.Columns.Add("datetime",typeof(DateTime));
Yes, you can specify the format string for that particular column:
yourDatagrid.Columns["datetime"].DefaultCellStyle.Format = "MM/dd/yyyy";
Please note: I'm not sure about wther Columns["datetime"]
is correct or not. if it gives error/not accessible means use the column index instead for column name yourDatagrid.Columns[4].DefaultCellStyle.Format = "MM/dd/yyyy";
You can change according to your need by doing this.
YourDataGrid.Columns["Column Name"].DefaultCellStyle.Format = "dd/MM/yyyy HH:mm:ss";