0

I am trying to change the format of the date to only show the date and not the time in a BoundColumn on a DataGrid but nothing I have tried has worked so far.

<asp:BoundColumn DataField="InvoiceDate" HeaderText="Date" DataFormatString = "{0:MM-dd-yyyy}"/>

I also tried:

DataFormatString="{0:dd-M-yyyy}"
DataFormatString="{0:d}"
DataFormatString="{0:MMM-d-yyy}"
user123456789
  • 1,914
  • 7
  • 44
  • 100

1 Answers1

0

This is the formatting string I use in my table which only shows the date:

<asp:BoundField HeaderText="Date" DataField="Date"
     SortExpression="Date" DataFormatString="{0:dd/MM/yyyy}" />

An interesting caveat is that this renders the date as if it were formatted with dd-MM-yyyy but regional settings might have a role to play in this.

Ortund
  • 8,095
  • 18
  • 71
  • 139
  • No didn't work, it's still showing the time on the grid. – user123456789 Jul 18 '17 at 11:13
  • Please update your question and show us a sample of the datetime values you're working with. I have a feeling that they aren't actually datetime values, but string values instead – Ortund Jul 18 '17 at 11:24
  • The field is datetime in the database and on the grid it shows as 03/06/2017 00:00:00 – user123456789 Jul 18 '17 at 11:34
  • Just wondering if adding HtmlEncode="false" within that control help? and since I don't know other idea, probably try DataFormatString="{0:d}" -- this is a short-hand version for date, but yours should have worked too. – hsoesanto Jul 18 '17 at 12:17