(How to convert) SQL Date type column shown as DateTime in grid

Despite SQL column is Date format (not DateTime format), corresponding column in grid is formatted as DateTime (time is added as 12.00.00 or similar). How can I convert this column format to Date only.

Thanks!

1 Reply

AR Arulpriya Ramalingam Syncfusion Team December 15, 2017 11:14 AM UTC

Hi Constantin, 
 
Thanks for contacting Syncfusion support. 
 
By default, the DataTime column will load the date in the format of dd/MM/yyyy hh:mm:ss.  
 
Suggestion 1 
 
In order to change the format of the DataTime column to display only the Date, the Format property can be used. Please make use of below code example and UG, 
 
Code example 
 
//To set the Format for the DateTime column 
this.gridGroupingControl1.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.Format = "dd/MM/yyyy"; 
 
Suggestion 2 
 
The QueryCellStyleInfo event can also be used to set the format for the DateTime column based on condition. In that event, the Format property of GridStyleInfo can be used to set the Format of the date. Please refer to the below code, 
 
Code example 
 
//Event Triggering 
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo; 
//Event Customization 
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    if (e.TableCellIdentity.Column == null) 
        return; 
    if(e.Style.CellValueType == typeof(DateTime) && e.TableCellIdentity.Column.Name == "ColumnName") 
    { 
        //To set the Format for the DateTime column 
        e.Style.Format = "dd/MM/yyyy"; 
    } 
} 
 
 
Regards, 
Arulpriya 


Loader.
Up arrow icon