SV 2005 date conversion error....baffled

  • Thread starter Thread starter Tim
  • Start date Start date
T

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
 
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.CreateTokenHashTable()
at System.Globalization.DateTimeFormatInfo.Tokenize(TokenType
TokenMask, TokenType& tokenType, Int32& tokenValue, __DTString& str)
at System.__DTString.GetSeparatorToken(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 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.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
 
Tim said:
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
 
Thanks for letting me know Matt, I was beginning to wonder if I was going
sane in a crazy world!

Tim
 
Back
Top