We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Formatting a shortDate/Time in the grid.

In the column definition of the grid I am able to format a date as follows

col.Field("CreateDate").Format("yMd").Add();

but I need to format the date/time as month/day/year hour:minutes.

I've tried some of the standard formats that I am aware of but have not been able to get any of them to work.

1 Reply

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 16, 2019 06:53 AM UTC

Hi John, 

Greetings from the Syncfusion support, 

We have validated query and we suggest you to use custom format to achieve your requirement. In the above sample, we have applied OrderDate column format as “MM/dd/yyyy”. Please refer the below code example and help documentation link for more information about custom date formatting. 

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).Load("onLoad").Columns(col => 
{ 
    col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
    col.Field("EmployeeID").HeaderText("EmployeeID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
    col.Field("CustomerID").HeaderText("CustomerName").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
    col.Field("OrderDate").HeaderText("Date").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
 
}).AllowPaging().AllowSelection(true).SelectionSettings(select=>select.Type(Syncfusion.EJ2.Grids.SelectionType.Multiple)).RowSelected("rowSelected").Render() 
 
<script> 
 
    function onLoad(args) { 
        this.columns[3].format = { type: "date", format: "MM/dd/yyyy" }; 
    } 


                                          https://ej2.syncfusion.com/aspnetmvc/documentation/common/internationalization/?no-cache=1#manipulating-datetime 

Regards, 
Seeni Sakthi Kumar S 


Loader.
Up arrow icon