Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dateFrom = Convert.ToDateTime(dr["DateFrom"]).ToString("dd/MM/yyyy");

I store my variable as string
Posted
Comments
CPallini 6-Feb-14 5:24am    
What you need to do? It is not clear to me, please elaborate.
Member 10574155 6-Feb-14 6:08am    
retrieve my data to a gridview, but my date is stored as a date data type, I declare it as string variable
agent_kruger 8-Feb-14 4:01am    
what do you want us to do with this code, sir?

DateTime dt = new DateTime();
dt = Convert.ToDateTime(dr["DateFrom"]);
string dateFrom = dt.ToString("dd/MM/yyyy");
 
Share this answer
 
This is the syntax:
C#
dateFrom = Convert.ToDateTime(dr["DateFrom"].ToString()).ToString("dd/MM/yyyy");

but actually I did not get that what do you want to ask...??
 
Share this answer
 
v2
Comments
Member 10574155 6-Feb-14 6:08am    
but this statement is giving me error, I cannot read my values
Er. Ajay Chauhan 6-Feb-14 6:32am    
can you elaborate what are you upto....??
Er. Ajay Chauhan 6-Feb-14 7:14am    
simply use dr["DateFrom"].ToString();
Member 10574155 6-Feb-14 7:03am    
Reading a date value from database
Member 10574155 6-Feb-14 7:21am    
How can .ToString() when it is a date data type in the database?

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