Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i converting text box values to date time then it shows error conversion failed error like-String was not recognized as a valid DateTime.
I have used conversion syntax like--

C#
System.DateTime date1 = Convert.ToDateTime(txtDate.Text.Trim());

 System.DateTime date2 = Convert.ToDateTime(txtCrDate.Text.Trim());

but it shows error like -String was not recognized as a valid DateTime.

Please help me to solve this problem.
Posted
Updated 13-Aug-13 0:46am
v2
Comments
CPallini 13-Aug-13 6:46am    
You should report the input string that caused the error.

1 solution

Try this:
C#
System.DateTime date1 = Convert.ToDateTime(txtDate.Text.Trim(), new CultureInfo("en-Us"));
 
Share this answer
 
Comments
Mukesh Bhagat 13-Aug-13 7:35am    
Thanks for helping...It works perfectly..

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