Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 1 textbox that contains the following data
C#
TextBox1.Text = "06/15/2013 22:22";
and
C#
_cultureInfo CultureInfo = new CultureInfo ("en-US", false);

but I used
C#
DateTime.ParseEtract (TextBox1.Text, "MM/dd/yyyy HH:mm", _cultureInfo);

error after convert: String was not recognized as a valid DateTime.
I am using convertdate but result :
25/05/2013 10:09:00 SA
I want result : 05/25/2013 10:09:00 SA
Posted
Updated 4-Oct-13 17:18pm
v4
Comments
BillWoodruff 5-Oct-13 1:22am    
Very important to paste in the actual code you are using.
Mike Meinz 5-Oct-13 7:30am    
That's not the actual code you are using. It has syntax errors due to misspelling.

You didn't publish your source code. You re-typed it and it has misspelled words and extra spaces. That makes it difficult to tell what you actually have in your program.

This code works for me using C# in Visual Studio 2012:
C#
CultureInfo c = new CultureInfo("en-US", false);
String s = "06/15/2013 22:22";
DateTime r = DateTime.ParseExact(s, "MM/dd/yyyy HH:mm", c);
Console.WriteLine(r.ToString("MM/dd/yyyy hh:mmtt",c))

Output:
Quote:
06/15/2013 10:22PM


See DateTime.ToString Method (String, IFormatProvider)[^]
 
Share this answer
 
v8
Comments
berrymaria 4-Oct-13 22:44pm    
+5!
hello professional


this link definitely help you...


String was not recognized as a valid DateTime.[^]


happy to help!!!
 
Share this answer
 
C#
DateTime.ParseEtract (TextBox1.Text, "MM / dd / yyyy HH: mm", _cultureInfo);


Your input string doesn't have spaces between all the elements, so why does your format string?

Should be:

C#
DateTime.ParseEtract (TextBox1.Text, "MM/dd/yyyy HH:mm", _cultureInfo);


Spaces are important, especially when using DateTime.ParseExact()
 
Share this answer
 
DateTime n=Convert.DateTime();
 
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