By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,711 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,711 IT Pros & Developers. It's quick & easy.

datetime convertion error

P: n/a
Good afternoon!
I have an error while trying to convert to DateTime ,here is the code
and the error:

ArrayList al = new ArrayList();
temp_str=Line.Split(' ');
al.Add(temp_str[0]); // value="11/02/2004"
al.Add(temp_str[1]); // value="10:53:10"

temp = String.Join(" ",temp_str2);

Now I am trying to do:
and gives me such error during the debugging: An unhandled exception
of type 'System.FormatException' occurred in mscorlib.dll

Additional information: String was not recognized as a valid DateTime.

Can anyone explain me why? Thank you very much.
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a

In seperated post I did show you something else than you show now.
(While others did show you other methods which are as well not the same as
you show now)

To keep it by the one I did, that was this, (I combined my last post by all
the previouw post when Bill wrote something about that.)

string[] str = {"11/02/04","11:23:00","AM"};
string mystring = String.Join(" ",str);
DateTime dta = Convert.ToDateTime(str,null);

The least you did not do in your post now is setting that second parameter
of the Convert.ToDateTime to "null", which means: set it to the setting of
the standard lanuguage and country setting of the computer.

I am not so known with the rules in this newsgroups, however in other dotnet
newsgroup it is normal to keep your messages in the same thread until it
changes completly.


Nov 16 '05 #2

P: n/a

I am not sure that my last post been posted so I am sorry if I post the
same question twice:
My problem in convertion is that I am trying to convert an American
format of date : 01/25/2004 and the convertion fails unless I use the
Europe type of convertion: 25/01/2004.
Is there a parameter that allows to convert date in American format?
Thank you very much !

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

P: n/a

Yes your original post is there and has two sample answers.
One from Jon Skeet and one from me..

Although I never like it to make dates computer setting independent, here my
sample fixed on the US culture.

DateTime dta = Convert.ToDateTime(mystring,
new System.Globalization.CultureInfo("en-US"));

(I saw there was a typo about mystring/str in my previous answer by the way)

Nov 16 '05 #4

P: n/a

It helped,Thank you!
*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.