I am pulling in date values from a sql server database using a gridview and and the date gets converted from
12/12/2009 to 12/12/2009 12:00:00 AM
How do I prevent that from happening ?
Thanks !
You can use the ToString()
method with a mask:
ToString("MM/dd/yyyy");
UPDATE: Just realized it would be easier in your case to do this in the grid view template
<asp:BoundField DataField="MyDate" DataFormatString="{0:MM/dd/yyyy}" />
You can set the date format in the bound column like this
<itemtemplate>
<asp id="Label1" runat="server" Label.Text='<%# Bind("YourDateField", "{0:M-dd-yyyy}") %>'>;
</asp>
</itemtemplate>