How can you display the date in a gridview as a single date rather than a datetime?

asp.net entity-framework gridview

Question

Using a gridview, I am importing date information from a SQL Server database, and the date is translated from

12/12/2009 to 12/12/2009 12:00:00 AM

How can I stop it from occurring?

thank you

1
22
8/4/2011 4:59:59 AM

Accepted Answer

The may be used toToString() technique using a mask:

ToString("MM/dd/yyyy");

UPDATE: I just thought that doing this in the grid view template might be simpler for you.

<asp:BoundField DataField="MyDate" DataFormatString="{0:MM/dd/yyyy}" />
44
4/9/2016 9:50:20 AM

Popular Answer

The bound column's date format may be adjusted as follows:

<itemtemplate>
<asp id="Label1" runat="server" Label.Text='<%# Bind("YourDateField", "{0:M-dd-yyyy}") %>'>;
</asp>
</itemtemplate>


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow