Search code examples
asp.netdatedatagridintegercustom-formatting

Custom format integer as date in DataGrid


I have an integer field in my database that contains a date value in the form yyyyMMdd. Is it possible to parse this as a date in the form dd/MM/yyyy as bound to a datagrid?

Currently the field is bound like this:

<asp:boundcolumn datafield="access_date" headertext="Last logged on"></asp:boundcolumn>

Solution

  • Why don't you use Date for dates in database ? You can convert int to datetime using following sample code:

    var sdate = intdate.ToString();
    var date = DateTime.ParseExact(sdate, "yyy/MM/dd", CultureInfo.InvariantCulture);