473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

datetime convertion error

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.
Nov 16 '05 #1
4 2085
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

Nov 16 '05 #2


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!
Nov 16 '05 #3
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
Nov 16 '05 #4

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
1
by: Vidar | last post by:
I have a problem in dotNET XSL convertion object. (XMLTRANSFORM) It won't convert UTF-8 to ISO-8859-1 I use this stylesheet for konvertion: <?xml version="1.0" encoding="ISO-8859-1"?> <!--...
3
by: juli | last post by:
How can I convert string into a datetime? Thanks!
8
by: Alan Silver | last post by:
Hello, I have a custom control that displays the date and time. I currently have properties for the day, month, year, hour and minute, which have to be set separately. This is inefficient. I...
4
by: kaikai | last post by:
Hi, I've got a problem while trying to make my source code clean. In a template: template<typename T> class A { public: T data; };
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
0
by: nmsreddi | last post by:
hello i am using c# as code behind .i have string date in my application ,i want to save this date value in my database sqlserver2000 which is declared as datetime. so i am converting date...
4
by: agarwalsunitadhn | last post by:
hi.. Currently i am facing a problem. I had a form containing two text boxes and in these two textboxes user fill up the date. and as per user's date i have to search in the data from the...
0
by: maolimix | last post by:
Hi to all, I have a trouble with datetime...now I explain.. I must to store to a C# variable the values from a "Datetime column" of Sql Server 2005. I tried 3 methods ...in the first two I never...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.