Click here to Skip to main content
15,908,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got the date like 2010-12-13 12:59:16.593 from the database in gridview i want to fornate date like 2010-12-13 in backhand how can i do that...
Posted

If you don't already have the date as an instance of the DateTime structure[^], use DateTime.TryParseExact()[^] to get it there.

Then, you can use the DateTime.ToString(string)[^] overload to specify what you want it to be displayed as.
 
Share this answer
 
v2
For display date time format 2010-12-13 in gridview

CSS
<asp:BoundField DataField="YourDateField" HeaderText="SomeHeader"
                    DataFormatString="{0:yyyy-MM-dd}"  />
 
Share this answer
 
v2
Comments
Rahul JR 13-Nov-13 5:46am    
thnks for replay but it doesn't works...
Check whether your column is taking datetime value but with a varchar format.

Column format should be DateTime then you can change it's format to
in Backend
date.ToString("yyyy-MM-dd");

and in Html gridview design side do as above article
DataFormatString="{0:yyyy-MM-dd}"

N.B.
Just make sure you set the HtmlEncode attribute to False or it won't work.
 
Share this answer
 
v2
why dont u extract date from datetime in backend
use it to get only date
CAST(convert(date, LastModified, 101) AS VARCHAR ) as LMDate

tell me if it doesn't work
 
Share this answer
 
Please refer below MSDN website. It will solve your problem

http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900