Click here to Skip to main content
15,896,500 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to retrieve date format data from database to textbox.my code attached here

SqlDataReader sdr=sda.ExecuteReader() if (sda.Read()==True)
Txtdateofbirth=sdr.GetValue(2).ToString();
but time also showing in text box..how to get date only in text box
Posted
Comments
Sergey Alexandrovich Kryukov 26-May-15 12:16pm    
ASP or ASP.NET?
Data format is irrelevant as soon as your database store time, not strings representing time.
—SA

Use the date format of your choice in the ToString

Txtdateofbirth=sdr.GetValue(2).ToString("dd/MM/yyyy");


Might need to cast it first though

Txtdateofbirth=((DateTime)sdr.GetValue(2)).ToString("dd/MM/yyyy");


This assumes the field is stored as a Date or DateTime field, if it isn't then it should be.
 
Share this answer
 
v2
Comments
Unni R 27-May-15 0:54am    
its not working ..showing DD/Jan/YYYY like that
F-ES Sitecore 27-May-15 4:03am    
The strings are case-sensitive, there is no valid "DD" or "YYYY" it is "dd" and "yyyy" exactly as I stated in my post.

https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
SqlDataAdapter sda=cmd.ExecuteReader();
While(sda.Read())
{
DateTime dt=Convert.ToDateTime(sda["DateOfBirth"]);
}
 
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