Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you show the date in a gridview as a date only instead of a datetime?

Tags:

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 !

like image 843
Mervin Avatar asked May 20 '11 17:05

Mervin


People also ask

How to display only date from DateTime in GridView?

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.


1 Answers

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}" /> 
like image 191
Ken Pespisa Avatar answered Oct 31 '22 18:10

Ken Pespisa