PC Review


Reply
Thread Tools Rate Thread

datetime convertion error

 
 
juli
Guest
Posts: n/a
 
      3rd Jan 2005
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_str2=(string[])al.ToArray(typeof(string));

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



Now I am trying to do:
date=Convert.ToDateTime(temp);
or
date=DateTime.Parse(temp);
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.
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      3rd Jan 2005
Juli,

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);
///

> date=Convert.ToDateTime(temp);


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.

Cor



 
Reply With Quote
 
juli jul
Guest
Posts: n/a
 
      3rd Jan 2005


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 http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      3rd Jan 2005
Juli,

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)

Cor


 
Reply With Quote
 
juli jul
Guest
Posts: n/a
 
      3rd Jan 2005

It helped,Thank you!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
field type convertion error Dan Microsoft C# .NET 7 20th Apr 2009 12:34 AM
type of data convertion error thread Microsoft Access 1 13th Apr 2007 02:42 PM
convertion error juli jul Microsoft C# .NET 3 12th Jan 2005 02:54 PM
convertion error juli Microsoft C# .NET 0 11th Jan 2005 02:29 PM
datetime convertion juli Microsoft C# .NET 3 2nd Jan 2005 12:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:55 AM.