Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
lbl_DateFrom.Text = carIndv.dateFrom.ToString("dd/MMM/yyyy");

//I storing this as Date
Posted
Comments
Simon_Whale 31-Jan-14 5:55am    
what value is in the carIndv.dateFrom property?

You wont be getting this error ( String was not recognized as a valid DateTime.) for the code provided by you..

C#
lbl_DateFrom.Text = carIndv.dateFrom.ToString("dd/MMM/yyyy");


check this post for the quoted error String was not recognized as a valid DateTime.[^]

This error you will get, when you are trying to cast invalid string object to DateTime
but you are doing the reverse, hopefully error shouldn't raise...
 
Share this answer
 
Comments
Rahul VB 31-Jan-14 11:49am    
Congrats man, 20K points. I remember seeing this question several times. Deja vu?
Karthik_Mahalingam 31-Jan-14 11:59am    
Thanks Rahul :)... every developer will come across this error
:)
Thomas Daniels 2-Feb-14 10:27am    
+5 it's indeed hard to find out the real problem if we don't have the full code.
Karthik_Mahalingam 2-Feb-14 11:01am    
Thanks ProgramFox :)
yes you are rite.
use :

Convert.ToDateTime(carIndv.dateFrom.ToString("dd/MM/yyyy"))
 
Share this answer
 
Hey, just try this:


Error in datetime variable[^]
 
Share this answer
 
lbl_DateFrom.Text = carIndv.dateFrom.ToString("dd/MM/yyyy");
 
Share this answer
 
Comments
Member 10548723 31-Jan-14 4:04am    
Still having the same error.
agent_kruger 3-Feb-14 9:14am    
sir, 1 point because "dd/MM/yyyy" and "dd/MMM/yyyy" makes no difference as in first case it shows "03/02/2014" and in second it shows "03/Feb/2014".

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