Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

When ever i gets data from sql server database table, date field is looks like below
9/11/2010 12:00:00 AM


how can i get date alone like
9/11/2010



Please advise me to get this

Thansk in advance

uday
Posted

Use Cast or Convert in SQL or ToString in code (dt.ToString("M/d/yyyy")).
Ref:http://msdn.microsoft.com/en-us/library/ms187928.aspx[^]
 
Share this answer
 
Comments
Uday P.Singh 12-Sep-11 7:05am    
my 5!
Prerak Patel 12-Sep-11 7:06am    
Thanks :)
Try this.
SQL
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]
 
Share this answer
 
Comments
Uday P.Singh 12-Sep-11 7:05am    
my 5!
Toniyo Jackson 12-Sep-11 7:07am    
Thanks Uday :)
P.Salini 12-Sep-11 7:09am    
Simple and Good answer
Try this:

SQL
SELECT CONVERT(VARCHAR(10),GETDATE(),111)


hope it helps :)
 
Share this answer
 
in the boundField in the gridview you can set the DataFormatString. see here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx[^]


DataFormatString="{0:dd/MM/yyyy"}
 
Share this answer
 
SELECT CONVERT(VARCHAR(10), columnName, 3) from tableName
 
Share this answer
 
Convert(varchar,date,101)

here retrieve "date" from database
 
Share this answer
 
CONVERT(varchar,yourdate,103) write this
 
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