How to set the custom date time format in WPF GridDataControl?
In GridDataControl, you can load DateTimeEdit CellType by defining GridDataDateTimeVisibleColumn or by setting CellType property of GridDataVisibleColumn.ColumnStyle to DateTimeEdit.
When you load DateTimeEdit Celltype, you can customize the format using DateTimePattern property of ColumnStyle.
The various formats available in DateTimePattern are as follows.
DateTimePattern name | Format | Example |
FullDateTime | Day, M d, yyyy HH:mm:ss | Monday, May 25, 2009 11:00:00 AM |
LongDate | Day M/d/yyyy | Monday may 25 2009 |
LongTime | HH:mm:ss AM/PM | 11:00:00 AM |
MonthDay | M d | may 25 |
RFC1123 | Day , d M yyyy HH:mm:ss GMT | mon,25 may 2009 11:00:00 GMT |
ShortDate | M/d/yyyy | 5/25/2009 |
ShortTime | HH:ss AM/PM | 11:00 AM |
SortableDateTime | yyyy-M-dT HH:mm:ss | 2009-05-25T11:00:00 |
UniversalSortableDateTime | yyyy-M-d HH:mm:ssZ | 2009-05-25 11:00:00Z |
YearMonth | M yyyy | May 2009 |
Where M= month, d=date, yyyy= year in four digits, HH= hour, mm=minutes, ss=seconds, Z= universal time designator.
In case, the default patterns do not meet your requirements, you can customize the date and time format by setting DateTimePattern Property as CustomPattern and define your own format for CustomPattern in the GridDataDateTimeEditInfo.
An example for custom format is displayed in the following code sample.
XAML
<syncfusion:GridDataDateTimeVisibleColumn HeaderText="joining date" MappingName="HireDate"> <syncfusion:GridDataDateTimeVisibleColumn.ColumnStyle> <syncfusion:GridDataColumnStyle> <syncfusion:GridDataColumnStyle.DateTimeEdit> <syncfusion:GridDateTimeEditStyleInfo CustomPattern=" M/d/yyyy HH:mm:ss" DateTimePattern="CustomPattern" /> </syncfusion:GridDataColumnStyle.DateTimeEdit> </syncfusion:GridDataColumnStyle> </syncfusion:GridDataDateTimeVisibleColumn.ColumnStyle> </syncfusion:GridDataDateTimeVisibleColumn>
Here the CustomPattern format is defined as “M/d/yyyy HH:mm:ss”. The following screenshot displays the output for the above code in the “GridDataControl”.
I hope you enjoyed learning about how to set the custom date time format in WPF GridDataControl.
You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!