This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C8E729.C2725F90
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,
I am trying to convert a string ("080714") to a date 08/07/14 using the =
format yyMMdd

mydate is declared as a date=20
grpod_date is the string 080714

I am getting the error "A first chance exception of type =
'System.FormatException' occurred in mscorlib.dll"
on the following line.
mydate =3D DateTime.ParseExact(gProd_date, "yyMMdd", New =
Globalization.CultureInfo("en-US"))

any guidance would be appreciated

Thank you

chuck



------=_NextPart_000_000A_01C8E729.C2725F90
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.6000.16674" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am trying to convert a string =
("080714") to a=20
date 08/07/14 using the format yyMMdd</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>mydate is declared as a date =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>grpod_date is the string =
080714</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I am getting the error "A first chance =
exception of=20
type 'System.FormatException' occurred in mscorlib.dll"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>on the following line.</FONT></DIV>
<DIV>
<P><FONT face=3DArial size=3D2>mydate =3D =
DateTime.ParseExact(gProd_date, "yyMMdd",=20
New Globalization.CultureInfo("en-US"))</FONT></P><FONT face=3DArial =
size=3D2>
<P><SPAN style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
'Arial','sans-serif'">any guidance=20
would be appreciated</SPAN></P>
<P><SPAN style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
'Arial','sans-serif'">Thank=20
you</SPAN></P>
<P><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
'Arial','sans-serif'">chuck</SPAN></P>
<P><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
'Arial','sans-serif'"></SPAN>&nbsp;</P></FONT></DIV></BODY></HTML>

------=_NextPart_000_000A_01C8E729.C2725F90--

Re: string converstion to a date by bpbrox

bpbrox
Wed Jul 16 14:06:04 CDT 2008

Chuck Hecht skrev:
> Hello,
> I am trying to convert a string ("080714") to a date 08/07/14 using the
> format yyMMdd
>
> mydate is declared as a date
> grpod_date is the string 080714
>
> I am getting the error "A first chance exception of type
> 'System.FormatException' occurred in mscorlib.dll"
> on the following line.
>
> mydate = DateTime.ParseExact(gProd_date, "yyMMdd", New
> Globalization.CultureInfo("en-US"))
>
> any guidance would be appreciated
> 080714


--
Bjørn Brox

Re: string converstion to a date by Chuck

Chuck
Wed Jul 16 14:22:16 CDT 2008

Bjorn,
I am not able to see your reply
chuck

"Bjørn Brox" <bpbrox@gmail.com> wrote in message
news:487e4695$1@news.broadpark.no...
> Chuck Hecht skrev:
>> Hello,
>> I am trying to convert a string ("080714") to a date 08/07/14 using the
>> format yyMMdd
>> mydate is declared as a date
>> grpod_date is the string 080714
>> I am getting the error "A first chance exception of type
>> 'System.FormatException' occurred in mscorlib.dll"
>> on the following line.
>>
>> mydate = DateTime.ParseExact(gProd_date, "yyMMdd", New
>> Globalization.CultureInfo("en-US"))
>>
>> any guidance would be appreciated
>> 080714
>
>
> --
> Bjørn Brox



Re: string converstion to a date by bpbrox

bpbrox
Wed Jul 16 14:34:23 CDT 2008

Chuck Hecht skrev:
> Bjorn,
> I am not able to see your reply
...
>>> mydate = DateTime.ParseExact(gProd_date, "yyMMdd", New
>>> Globalization.CultureInfo("en-US"))
>>>
Sorry...

Try to use null instead of the Globalization parameter, - you don't need
it since you are parsing only numbers.

Anyhow: This should not be your problem.

Are you really sure that your input string is exactly in the format
"yyMMdd"?

Try to debug.
--
Bjørn Brox

Re: string converstion to a date by Chuck

Chuck
Wed Jul 16 15:23:37 CDT 2008

I tried null first and it casued other issues. Another blogger recommended
the Globalization parameter.
the "date" value is pulled form a scanned barcode and is only 6 or 8
numbers. The format is also provided
by the customer as yyMMdd or MMddyyyyy. Anyways do I need to manually insert
the "/" seperators and
have it in date form before I pass it? I have just been passing a string of
just numbers like 080716


"Bjørn Brox" <bpbrox@gmail.com> wrote in message
news:487e4d37$1@news.broadpark.no...
> Chuck Hecht skrev:
>> Bjorn,
>> I am not able to see your reply
> ...
>>>> mydate = DateTime.ParseExact(gProd_date, "yyMMdd", New
>>>> Globalization.CultureInfo("en-US"))
>>>>
> Sorry...
>
> Try to use null instead of the Globalization parameter, - you don't need
> it since you are parsing only numbers.
>
> Anyhow: This should not be your problem.
>
> Are you really sure that your input string is exactly in the format
> "yyMMdd"?
>
> Try to debug.
> --
> Bjørn Brox



Re: string converstion to a date by bpbrox

bpbrox
Wed Jul 16 16:56:41 CDT 2008

Chuck Hecht skrev:
> I tried null first and it casued other issues. Another blogger recommended
> the Globalization parameter.
> the "date" value is pulled form a scanned barcode and is only 6 or 8
> numbers.

Well, I guess you hit the 8-numbers variant, trying to parse it as the
6-digit variant.

Why don't you just debug the code, seeing what the reason is for the crash?

Or use a try/catch to trap the error.

try
{
mydate = DateTime.ParseExact(gProd_date, "yyMMdd", null);
}
catch
{
MessageWindow.Show(String.Format("Got a crash parsing
gProd_date='{0}'", gProd_date ?? "<null>"));
}

The format is also provided
> by the customer as yyMMdd or MMddyyyyy. Anyways do I need to manually insert
> the "/" seperators and
> have it in date form before I pass it? I have just been passing a string of
> just numbers like 080716
>
No, that's why you are using the format parameter.

--
Bjørn Brox

Re: string converstion to a date by Chuck

Chuck
Wed Jul 16 17:28:38 CDT 2008

I have used the debugger thats how I have seen the error.
I have tried using NULL as you recommend and I get the following from vb
at design time.

"Null" is not declared. Null Constant is no longer supported; use
System.DBNull instead."

I tried System.dbnull but was told by vb that:

DBNULL is a type in System and can not be used as an expression.






"Bjørn Brox" <bpbrox@gmail.com> wrote in message
news:487e6e92$1@news.broadpark.no...
> Chuck Hecht skrev:
>> I tried null first and it casued other issues. Another blogger
>> recommended the Globalization parameter.
>> the "date" value is pulled form a scanned barcode and is only 6 or 8
>> numbers.
>
> Well, I guess you hit the 8-numbers variant, trying to parse it as the
> 6-digit variant.
>
> Why don't you just debug the code, seeing what the reason is for the
> crash?
>
> Or use a try/catch to trap the error.
>
> try
> {
> mydate = DateTime.ParseExact(gProd_date, "yyMMdd", null);
> }
> catch
> {
> MessageWindow.Show(String.Format("Got a crash parsing
> gProd_date='{0}'", gProd_date ?? "<null>"));
> }
>
> The format is also provided
>> by the customer as yyMMdd or MMddyyyyy. Anyways do I need to manually
>> insert the "/" seperators and
>> have it in date form before I pass it? I have just been passing a string
>> of just numbers like 080716
>>
> No, that's why you are using the format parameter.
>
> --
> Bjørn Brox



Re: string converstion to a date by Chris

Chris
Wed Jul 16 17:48:25 CDT 2008

The VB equivalent for null is Nothing.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

"Chuck Hecht" <checht@trakersystems.com> wrote in message
news:Ook3YL55IHA.5108@TK2MSFTNGP06.phx.gbl...
>I have used the debugger thats how I have seen the error.
> I have tried using NULL as you recommend and I get the following from vb
> at design time.
>
> "Null" is not declared. Null Constant is no longer supported; use
> System.DBNull instead."
>
> I tried System.dbnull but was told by vb that:
>
> DBNULL is a type in System and can not be used as an expression.
>
>
>
>
>
>
> "Bjørn Brox" <bpbrox@gmail.com> wrote in message
> news:487e6e92$1@news.broadpark.no...
>> Chuck Hecht skrev:
>>> I tried null first and it casued other issues. Another blogger
>>> recommended the Globalization parameter.
>>> the "date" value is pulled form a scanned barcode and is only 6 or 8
>>> numbers.
>>
>> Well, I guess you hit the 8-numbers variant, trying to parse it as the
>> 6-digit variant.
>>
>> Why don't you just debug the code, seeing what the reason is for the
>> crash?
>>
>> Or use a try/catch to trap the error.
>>
>> try
>> {
>> mydate = DateTime.ParseExact(gProd_date, "yyMMdd", null);
>> }
>> catch
>> {
>> MessageWindow.Show(String.Format("Got a crash parsing
>> gProd_date='{0}'", gProd_date ?? "<null>"));
>> }
>>
>> The format is also provided
>>> by the customer as yyMMdd or MMddyyyyy. Anyways do I need to manually
>>> insert the "/" seperators and
>>> have it in date form before I pass it? I have just been passing a string
>>> of just numbers like 080716
>>>
>> No, that's why you are using the format parameter.
>>
>> --
>> Bjørn Brox
>
>



Re: string converstion to a date by srhartone

srhartone
Sun Jul 20 14:23:02 CDT 2008

Probably the best solution is to implement a IFormatProvider class to handle
your custom date which will then be abstracted away from your app. Search
MSDN for examples. Don't rely on the DateTime class to format your date
correctly, that input format is not US format.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


"Chuck Hecht" wrote:

> I have used the debugger thats how I have seen the error.
> I have tried using NULL as you recommend and I get the following from vb
> at design time.
>
> "Null" is not declared. Null Constant is no longer supported; use
> System.DBNull instead."
>
> I tried System.dbnull but was told by vb that:
>
> DBNULL is a type in System and can not be used as an expression.
>
>
>
>
>
>
> "Bjørn Brox" <bpbrox@gmail.com> wrote in message
> news:487e6e92$1@news.broadpark.no...
> > Chuck Hecht skrev:
> >> I tried null first and it casued other issues. Another blogger
> >> recommended the Globalization parameter.
> >> the "date" value is pulled form a scanned barcode and is only 6 or 8
> >> numbers.
> >
> > Well, I guess you hit the 8-numbers variant, trying to parse it as the
> > 6-digit variant.
> >
> > Why don't you just debug the code, seeing what the reason is for the
> > crash?
> >
> > Or use a try/catch to trap the error.
> >
> > try
> > {
> > mydate = DateTime.ParseExact(gProd_date, "yyMMdd", null);
> > }
> > catch
> > {
> > MessageWindow.Show(String.Format("Got a crash parsing
> > gProd_date='{0}'", gProd_date ?? "<null>"));
> > }
> >
> > The format is also provided
> >> by the customer as yyMMdd or MMddyyyyy. Anyways do I need to manually
> >> insert the "/" seperators and
> >> have it in date form before I pass it? I have just been passing a string
> >> of just numbers like 080716
> >>
> > No, that's why you are using the format parameter.
> >
> > --
> > Bjørn Brox
>
>
>