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 have to Create a BoundField, set its properties including the property dataformatstring which you can use to set format of the field appear in the GridView, and add it to the GridView control.
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}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With