asp DataGrid Format Text Field as DateTime
asp DataGrid Format Text Field as DateTime
Here Im binding to a DataGrid on an asp page, the Database contains a text field that holds a date text on the format "yyyyMMdd" and I want to show the date in the format "day MonthName year",
All I had to do is adding to the Datagrid <Columns> a TemplateColumn with the following binding:
<# DateTime.ParseExact(DataBinder.Eval(Container.DataItem, "DATE_Field").ToString(), "yyyyMMdd", newSystem.Globalization.CultureInfo("ar-sa")).ToString("dd MMM yyyy", newSystem.Globalization.CultureInfo("ar-sa"))%>
For example, lets say the database stores "14350117" in the field DATE_Field as text, the above binding will let it appear as
on the page..
on the page..