471,627 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

SV 2005 date conversion error....baffled

Tim
Hi,

The following code works just fine in VS 2003 but in VS 2005 I am getting an
error:

The code:
DateTime dClose = System.Convert.ToDateTime(now.Date.ToString("MMM dd,
yyyy") + " " + storeClose.Hour + ":" + storeClose.Minute);

The error:
threw an exception of type 'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

now.Date.ToString("MMM dd, yyyy") gives me "Jan 09, 2006"
storeClose.Hour gives me 17
storeClose.Minute gives me 30

The whole string is "Jan 09, 2006 17:30" which should convert to a date no
problem. Can someone help?

Tim
Jan 9 '06 #1
3 2434
Tim
I made it real simple; I put this line in its own project

System.Convert.ToDateTime("01/01/2006");

and I am still getting
'Index was outside the bounds of the array.' - what array?

These are the details...

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.GetSeparatorToken(DateTimeFormat Info 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 TestApp.Form1..ctor() in C:\Documents and Settings\Tim\My
Documents\Visual Studio 2005\Projects\TestApp\TestApp\Form1.cs:line 17
at TestApp.Program.Main() in C:\Documents and Settings\Tim\My
Documents\Visual Studio 2005\Projects\TestApp\TestApp\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(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()

"Tim" <ti*@home.com> wrote in message
news:YS******************@news20.bellglobal.com...
Hi,

The following code works just fine in VS 2003 but in VS 2005 I am getting
an error:

The code:
DateTime dClose = System.Convert.ToDateTime(now.Date.ToString("MMM dd,
yyyy") + " " + storeClose.Hour + ":" + storeClose.Minute);

The error:
threw an exception of type 'System.IndexOutOfRangeException'
base {System.SystemException}: {"Index was outside the bounds of the
array."}

now.Date.ToString("MMM dd, yyyy") gives me "Jan 09, 2006"
storeClose.Hour gives me 17
storeClose.Minute gives me 30

The whole string is "Jan 09, 2006 17:30" which should convert to a date no
problem. Can someone help?

Tim

Jan 9 '06 #2

Tim wrote:
I made it real simple; I put this line in its own project

System.Convert.ToDateTime("01/01/2006");

and I am still getting
'Index was outside the bounds of the array.' - what array?


Hm. Something else is going on. I tried that exact thing (as well as
your
first example) in VS2005. It worked fine, as expected. You may have a
corrupted library or something.

Matt

Jan 9 '06 #3
Tim
Thanks for letting me know Matt, I was beginning to wonder if I was going
sane in a crazy world!

Tim

"Matt" <ma********@sprynet.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Tim wrote:
I made it real simple; I put this line in its own project

System.Convert.ToDateTime("01/01/2006");

and I am still getting
'Index was outside the bounds of the array.' - what array?


Hm. Something else is going on. I tried that exact thing (as well as
your
first example) in VS2005. It worked fine, as expected. You may have a
corrupted library or something.

Matt

Jan 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by sathyashrayan | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.