Help with this invalid date string

blueeyes53

Active member
Joined
May 2, 2006
Messages
25
Programming Experience
Beginner
pintMonth = ToDateTime(pstrFields(0)). Month - 1

This code when debug gives this message code:

An unhandled exception of type " System.FormatException occurred in mscorlib.dll

Additional information :
String information : String was not recognized as a ValidDateTime

This code has called into another function. When that function is finished, this is the next statement that will be executed.

Anyone could help!
Thanks
 
Well what does pstrFields(0) contain? Also, what does the ToDateTime function do exactly? As far as I'm aware there is no ToDateTime function in VB.NET so it must be one of your own. Basically, there are two ways to convert a String to a Date in VB.NET 2003: Date.Parse and Date.ParseExact. Parse will convert a string from any one of a number of recognised standard formats to a Date object and throw an exception if the string is in an unrecognised format. That's what is happening in your code I'll wager. ParseExact allows you to specify a format that is not recognised by Parse, like "yyyyMMdd", but the string must be in that specific format or an exception is thrown. If your string is not in a standard format and you don't know the format that it is in then you're buggered. Note that you can call the IsDate function but all it does is call Parse and catch the exception if it fails.

Also, what has this question got to do with Windows Forms? Please atke the time and make the effort to post in the most appropriate forum to make the site easier to use for everyone. Moved.
 
Back
Top