473,403 Members | 2,183 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,403 software developers and data experts.

.NET 2.0 DateTime conversion error??

Tim
Hi,

I am trying to do something simple. Convert a string date to datetime but it
is not working and is giving me a baffling error!

System.Convert.ToDateTime("Jan 30, 2006")
'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

System.Convert.ToDateTime("01/01/2006")
'System.Convert.ToDateTime("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}
System.Convert.ToDateTime(fParams.dtStartDate.Valu e)

Huh? What array is it talking about? I have done this many times in .NET 1.1
and it works just fine. This is a project that I have converted from .NET
1.1. The conversion was successful and it compiles with no errors, so what
is going on?

Please help, completely baffled.

Tim


Jan 31 '06 #1
11 2781
On Mon, 30 Jan 2006 19:13:30 -0500, "Tim" <ti******@sympatico.ca>
wrote:
Hi,

I am trying to do something simple. Convert a string date to datetime but it
is not working and is giving me a baffling error!

System.Convert.ToDateTime("Jan 30, 2006")
'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

System.Convert.ToDateTime("01/01/2006")
'System.Convert.ToDateTime("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}
System.Convert.ToDateTime(fParams.dtStartDate.Val ue)

Huh? What array is it talking about? I have done this many times in .NET 1.1
and it works just fine. This is a project that I have converted from .NET
1.1. The conversion was successful and it compiles with no errors, so what
is going on?

Please help, completely baffled.

Tim


Try this:

DateTime dt = DateTime.Parse("01/01/2006");
DateTime dte = DateTime.Parse("Jan 30, 2006");
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Jan 31 '06 #2
Tim
Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

That damn array just won't go away! Any more ideas?

Tim

Otis Mukinfus" <ph***@emailaddress.com> wrote in message
news:m9********************************@4ax.com...
On Mon, 30 Jan 2006 19:13:30 -0500, "Tim" <ti******@sympatico.ca>
wrote:
Hi,

I am trying to do something simple. Convert a string date to datetime but
it
is not working and is giving me a baffling error!

System.Convert.ToDateTime("Jan 30, 2006")
'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

System.Convert.ToDateTime("01/01/2006")
'System.Convert.ToDateTime("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}
System.Convert.ToDateTime(fParams.dtStartDate.Va lue)

Huh? What array is it talking about? I have done this many times in .NET
1.1
and it works just fine. This is a project that I have converted from .NET
1.1. The conversion was successful and it compiles with no errors, so what
is going on?

Please help, completely baffled.

Tim


Try this:

DateTime dt = DateTime.Parse("01/01/2006");
DateTime dte = DateTime.Parse("Jan 30, 2006");
Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Jan 31 '06 #3

"Tim" <ti******@sympatico.ca> wrote in message news:v1*******************@news20.bellglobal.com.. .
Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type 'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the array."}

That damn array just won't go away! Any more ideas?


Possibly because THAT DAMN ARRAY is the real problem.
I suspect that the Date conversion is NOT the cause of your problem.
Put some displays in or step through in debug.
Find the real cause of your problem

Hope this helps
Bill
Jan 31 '06 #4
DateTime dt = System.Convert.ToDateTime("01/01/2006");
Console.WriteLine(dt);
dt = DateTime.Parse("01/01/2006");

Works here. You got something else going on. Post your code.
--
William Stacey [MVP]

"Tim" <ti******@sympatico.ca> wrote in message
news:v1*******************@news20.bellglobal.com.. .
| Hi Otis,
|
| Thanks for the reply, however this also fails on my system.
|
| DateTime.Parse("01/01/2006")
| 'DateTime.Parse("01/01/2006")' threw an exception of type
| 'System.IndexOutOfRangeException'
| base {System.SystemException}: {"Index was outside the bounds of the
| array."}
|
| That damn array just won't go away! Any more ideas?
|
| Tim
|
| Otis Mukinfus" <ph***@emailaddress.com> wrote in message
| news:m9********************************@4ax.com...
| > On Mon, 30 Jan 2006 19:13:30 -0500, "Tim" <ti******@sympatico.ca>
| > wrote:
| >
| >>Hi,
| >>
| >>I am trying to do something simple. Convert a string date to datetime
but
| >>it
| >>is not working and is giving me a baffling error!
| >>
| >>System.Convert.ToDateTime("Jan 30, 2006")
| >>'System.Convert.ToDateTime("Jan 30, 2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>
| >>System.Convert.ToDateTime("01/01/2006")
| >>'System.Convert.ToDateTime("01/01/2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>System.Convert.ToDateTime(fParams.dtStartDate.Va lue)
| >>
| >>Huh? What array is it talking about? I have done this many times in .NET
| >>1.1
| >>and it works just fine. This is a project that I have converted from
..NET
| >>1.1. The conversion was successful and it compiles with no errors, so
what
| >>is going on?
| >>
| >>Please help, completely baffled.
| >>
| >>Tim
| >>
| >>
| >>
| >
| > Try this:
| >
| > DateTime dt = DateTime.Parse("01/01/2006");
| > DateTime dte = DateTime.Parse("Jan 30, 2006");
| >
| >
| > Otis Mukinfus
| > http://www.otismukinfus.com
| > http://www.tomchilders.com
|
|
Jan 31 '06 #5
On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <ti******@sympatico.ca>
wrote:
Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

That damn array just won't go away! Any more ideas?

Tim

[snip]

Gosh, Tim! I think something else is wrong. Have you stepped through
the code with the debugger (I mean ALL the lines before the method
calls)? It ain't happening in the code I sent you.

Paste the code below into a NEW console application, replacing all of
the default code and see what happens:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
DateTime dt = DateTime.Parse("01/01/2006");
DateTime dte = DateTime.Parse("Jan 30, 2006");
}
}
}

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Jan 31 '06 #6
Tim
Hi Otis,

I pasted the code you gave me into a console application, ran it and got the
exact same error. It would seem to make sense that it is not in the datetime
convert function, however what array is it talking about?

The error seems to originate from mscorlib.dll. Does that make any sense? I
have a clean install of XP pro with .NET 2.0 on it. I had this problem on my
other machine and I orginally thought it was because I had .NET 1.1 and .NET
2.0 on the same machine.

I have done this datetime conversion function many times with .NET 1.1, so
that is why I am so baffled.

Tim

"Otis Mukinfus" <ph***@emailaddress.com> wrote in message
news:oc********************************@4ax.com...
On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <ti******@sympatico.ca>
wrote:
Hi Otis,

Thanks for the reply, however this also fails on my system.

DateTime.Parse("01/01/2006")
'DateTime.Parse("01/01/2006")' threw an exception of type
'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

That damn array just won't go away! Any more ideas?

Tim

[snip]

Gosh, Tim! I think something else is wrong. Have you stepped through
the code with the debugger (I mean ALL the lines before the method
calls)? It ain't happening in the code I sent you.

Paste the code below into a NEW console application, replacing all of
the default code and see what happens:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
DateTime dt = DateTime.Parse("01/01/2006");
DateTime dte = DateTime.Parse("Jan 30, 2006");
}
}
}

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com

Jan 31 '06 #7
Try/catch the exception and write it to the console an post here. This is
weird.

--
William Stacey [MVP]

"Tim" <ti******@sympatico.ca> wrote in message
news:LD*******************@news20.bellglobal.com.. .
| Hi Otis,
|
| I pasted the code you gave me into a console application, ran it and got
the
| exact same error. It would seem to make sense that it is not in the
datetime
| convert function, however what array is it talking about?
|
| The error seems to originate from mscorlib.dll. Does that make any sense?
I
| have a clean install of XP pro with .NET 2.0 on it. I had this problem on
my
| other machine and I orginally thought it was because I had .NET 1.1 and
..NET
| 2.0 on the same machine.
|
| I have done this datetime conversion function many times with .NET 1.1, so
| that is why I am so baffled.
|
| Tim
|
| "Otis Mukinfus" <ph***@emailaddress.com> wrote in message
| news:oc********************************@4ax.com...
| > On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <ti******@sympatico.ca>
| > wrote:
| >
| >>Hi Otis,
| >>
| >>Thanks for the reply, however this also fails on my system.
| >>
| >>DateTime.Parse("01/01/2006")
| >>'DateTime.Parse("01/01/2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>
| >>That damn array just won't go away! Any more ideas?
| >>
| >>Tim
| > [snip]
| >
| > Gosh, Tim! I think something else is wrong. Have you stepped through
| > the code with the debugger (I mean ALL the lines before the method
| > calls)? It ain't happening in the code I sent you.
| >
| > Paste the code below into a NEW console application, replacing all of
| > the default code and see what happens:
| >
| > using System;
| > using System.Collections.Generic;
| > using System.Text;
| > using System.Data;
| >
| > namespace TestConsole
| > {
| > class Program
| > {
| > static void Main(string[] args)
| > {
| > DateTime dt = DateTime.Parse("01/01/2006");
| > DateTime dte = DateTime.Parse("Jan 30, 2006");
| > }
| > }
| > }
| >
| > Otis Mukinfus
| > http://www.otismukinfus.com
| > http://www.tomchilders.com
|
|
Jan 31 '06 #8
Other thing. What language version of Windows and .Net 2.0?

--
William Stacey [MVP]

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
| Try/catch the exception and write it to the console an post here. This is
| weird.
|
| --
| William Stacey [MVP]
|
| "Tim" <ti******@sympatico.ca> wrote in message
| news:LD*******************@news20.bellglobal.com.. .
|| Hi Otis,
||
|| I pasted the code you gave me into a console application, ran it and got
| the
|| exact same error. It would seem to make sense that it is not in the
| datetime
|| convert function, however what array is it talking about?
||
|| The error seems to originate from mscorlib.dll. Does that make any sense?
| I
|| have a clean install of XP pro with .NET 2.0 on it. I had this problem on
| my
|| other machine and I orginally thought it was because I had .NET 1.1 and
| .NET
|| 2.0 on the same machine.
||
|| I have done this datetime conversion function many times with .NET 1.1,
so
|| that is why I am so baffled.
||
|| Tim
||
|| "Otis Mukinfus" <ph***@emailaddress.com> wrote in message
|| news:oc********************************@4ax.com...
|| > On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <ti******@sympatico.ca>
|| > wrote:
|| >
|| >>Hi Otis,
|| >>
|| >>Thanks for the reply, however this also fails on my system.
|| >>
|| >>DateTime.Parse("01/01/2006")
|| >>'DateTime.Parse("01/01/2006")' threw an exception of type
|| >>'System.IndexOutOfRangeException'
|| >>base {System.SystemException}: {"Index was outside the bounds of the
|| >>array."}
|| >>
|| >>That damn array just won't go away! Any more ideas?
|| >>
|| >>Tim
|| > [snip]
|| >
|| > Gosh, Tim! I think something else is wrong. Have you stepped through
|| > the code with the debugger (I mean ALL the lines before the method
|| > calls)? It ain't happening in the code I sent you.
|| >
|| > Paste the code below into a NEW console application, replacing all of
|| > the default code and see what happens:
|| >
|| > using System;
|| > using System.Collections.Generic;
|| > using System.Text;
|| > using System.Data;
|| >
|| > namespace TestConsole
|| > {
|| > class Program
|| > {
|| > static void Main(string[] args)
|| > {
|| > DateTime dt = DateTime.Parse("01/01/2006");
|| > DateTime dte = DateTime.Parse("Jan 30, 2006");
|| > }
|| > }
|| > }
|| >
|| > Otis Mukinfus
|| > http://www.otismukinfus.com
|| > http://www.tomchilders.com
||
||
|
|
Feb 1 '06 #9
On Tue, 31 Jan 2006 07:22:05 -0500, "Tim" <ti******@sympatico.ca>
wrote:
Hi Otis,

I pasted the code you gave me into a console application, ran it and got the
exact same error. It would seem to make sense that it is not in the datetime
convert function, however what array is it talking about?

The error seems to originate from mscorlib.dll. Does that make any sense? I
have a clean install of XP pro with .NET 2.0 on it. I had this problem on my
other machine and I orginally thought it was because I had .NET 1.1 and .NET
2.0 on the same machine.

I have done this datetime conversion function many times with .NET 1.1, so
that is why I am so baffled.

Tim

[snip]

I'm stupefied Tim. I can't imagine what it could be.

Otis Mukinfus
http://www.otismukinfus.com
http://www.tomchilders.com
Feb 1 '06 #10
Hi William,

I have reached the conclusion that something is corrupted somewhere. I even
tried
DateTime dt = System.Convert.ToDateTime("fishcakes");
and got the same error as below, it didn't even try to convert it.

Using C# on XP Pro SP2, US English, P4 2.6

Tim
System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
Source="mscorlib"
StackTrace:
at System.Globalization.DateTimeFormatInfo.InsertHash (TokenHashValue[]
hashTable, String str, TokenType tokenType, Int32 tokenValue)
at System.Globalization.DateTimeFormatInfo.CreateToke nHashTable()
at System.Globalization.DateTimeFormatInfo.Tokenize(T okenType
TokenMask, TokenType& tokenType, Int32& tokenValue, __DTString& str)
at System.__DTString.GetRegularToken(TokenType& tokenType,
Int32& tokenValue, DateTimeFormatInfo dtfi)
at System.DateTimeParse.Lex(DS dps, __DTString& str,
DateTimeToken& dtok, DateTimeRawInfo& raw, DateTimeResult& result,
DateTimeFormatInfo& dtfi)
at System.DateTimeParse.TryParse(String s, DateTimeFormatInfo
dtfi, DateTimeStyles styles, DateTimeResult& result)
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo
dtfi, DateTimeStyles styles)
at System.DateTime.Parse(String s, IFormatProvider provider)
at System.Convert.ToDateTime(String value)
at ConsoleApplication1.Program.Main(String[] args) in
C:\Documents and Settings\Tim\My Documents\Visual Studio
2005\Projects\ConsoleApplication1\ConsoleApplicati on1\Program.cs:line
12
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Try/catch the exception and write it to the console an post here. This is
weird.

--
William Stacey [MVP]

"Tim" <ti******@sympatico.ca> wrote in message
news:LD*******************@news20.bellglobal.com.. .
| Hi Otis,
|
| I pasted the code you gave me into a console application, ran it and got
the
| exact same error. It would seem to make sense that it is not in the
datetime
| convert function, however what array is it talking about?
|
| The error seems to originate from mscorlib.dll. Does that make any
sense?
I
| have a clean install of XP pro with .NET 2.0 on it. I had this problem
on
my
| other machine and I orginally thought it was because I had .NET 1.1 and
.NET
| 2.0 on the same machine.
|
| I have done this datetime conversion function many times with .NET 1.1,
so
| that is why I am so baffled.
|
| Tim
|
| "Otis Mukinfus" <ph***@emailaddress.com> wrote in message
| news:oc********************************@4ax.com...
| > On Mon, 30 Jan 2006 20:26:43 -0500, "Tim" <ti******@sympatico.ca>
| > wrote:
| >
| >>Hi Otis,
| >>
| >>Thanks for the reply, however this also fails on my system.
| >>
| >>DateTime.Parse("01/01/2006")
| >>'DateTime.Parse("01/01/2006")' threw an exception of type
| >>'System.IndexOutOfRangeException'
| >>base {System.SystemException}: {"Index was outside the bounds of the
| >>array."}
| >>
| >>That damn array just won't go away! Any more ideas?
| >>
| >>Tim
| > [snip]
| >
| > Gosh, Tim! I think something else is wrong. Have you stepped through
| > the code with the debugger (I mean ALL the lines before the method
| > calls)? It ain't happening in the code I sent you.
| >
| > Paste the code below into a NEW console application, replacing all of
| > the default code and see what happens:
| >
| > using System;
| > using System.Collections.Generic;
| > using System.Text;
| > using System.Data;
| >
| > namespace TestConsole
| > {
| > class Program
| > {
| > static void Main(string[] args)
| > {
| > DateTime dt = DateTime.Parse("01/01/2006");
| > DateTime dte = DateTime.Parse("Jan 30, 2006");
| > }
| > }
| > }
| >
| > Otis Mukinfus
| > http://www.otismukinfus.com
| > http://www.tomchilders.com
|
|

Feb 1 '06 #11


Tim

Did you ever resolve your date conversion (Index outside bounds of
array) error when using CDate?

I am having the same problem, it is a very strange error when doing
something so simple.

Look forward to hearing how you fixed this.

Stephen
*** Sent via Developersdex http://www.developersdex.com ***
Sep 18 '06 #12

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

Similar topics

3
by: sunny076 | last post by:
Hi, I am trying to convert from Julian to Gregorian data in C#. I was exploring teh JulianCalendar and Gregorian calendar classes but still not sure how I can do it. For example, the Julian date...
3
by: Christopher Crooker | last post by:
We had a function with the signature: Function(Object *, DateTime, DateTime, EnumType) and then changed the class some and there was a 4 parameter function with the signature: ...
14
by: Bob Day | last post by:
using VS 2003, VB.net... Why is this valid: dim x as datetime = nothing but this is invalid: public sub DoSomething (Optional byval x as datetime = nothing) ....code to do something end...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
1
by: Untitled | last post by:
I have an application that stores all DateTime inforamtion in UTC. However, this application will be accessed from arround the world. I would like my users to be able to specify their prefered...
9
by: Hrvoje Voda | last post by:
How to convert text from textbox "12.05.1977" into "12/05/1977"? and also check if the text is in right format before converting? Hrcko
11
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I have a SQL database table with rows in which the primary key is a DateTime type (although I don't use the Time part). Have added numerous rows and now want to delete one so I enter the date...
1
Manikgisl
by: Manikgisl | last post by:
But the problem is we have dates in Varchar instead Datetime While Converting Varchar To Datetime All four formats are unable to Convert ie select Convert(Datetime,'18-11-2008 2:35:19...
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.