Home All Groups Group Topic Archive Search About

VB.NET (ASP) Can't convert Dates...help!

Author
29 Mar 2005 11:17 AM
Scott H
I've converted string representations of Dates into DATE types alot
before in Windows Apps, I'm just doing the same now in a Web App, I'm
fairly new to ASP.NET, but the error does not make sense at all:

System.InvalidCastException: Cast from string "14:13:00 21/03/2005" to
type 'Date' is not valid.

To which I reply "yes it #!$%#% is!!"
Now, I've seen it before where you try to convert an empty string to a
date, and of course the poor thing can't convert it, but the above
looks like a date to me...I'm in the UK so 21 is the day not the
month. Maybe this is what its refering to, I have the regional
settings, set to UK style dates, so it should be able to interpret it.

So, whats happening here?

Scott

Author
29 Mar 2005 11:34 AM
Ken Tucker [MVP]
Hi,

Dim d As DateTime = DateTime.ParseExact("14:13:00 21/03/2005", "HH:mm:ss
dd/MM/yyyy", New Globalization.CultureInfo("en-US"))



Ken

--------------------

"Scott H" <e@mc.sqr> wrote in message
news:esdi41tofs4toa4efg23567nh0t9mdp47f@4ax.com...

I've converted string representations of Dates into DATE types alot
before in Windows Apps, I'm just doing the same now in a Web App, I'm
fairly new to ASP.NET, but the error does not make sense at all:

System.InvalidCastException: Cast from string "14:13:00 21/03/2005" to
type 'Date' is not valid.

To which I reply "yes it #!$%#% is!!"
Now, I've seen it before where you try to convert an empty string to a
date, and of course the poor thing can't convert it, but the above
looks like a date to me...I'm in the UK so 21 is the day not the
month. Maybe this is what its refering to, I have the regional
settings, set to UK style dates, so it should be able to interpret it.

So, whats happening here?

Scott
Author
29 Mar 2005 2:50 PM
Scott H
Thanks Ken, that worked

Scott

On Tue, 29 Mar 2005 06:34:33 -0500, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:

Show quoteHide quote
>Hi,
>
>Dim d As DateTime = DateTime.ParseExact("14:13:00 21/03/2005", "HH:mm:ss
>dd/MM/yyyy", New Globalization.CultureInfo("en-US"))
>
>
>
>Ken
>
>--------------------
>
>"Scott H" <e@mc.sqr> wrote in message
>news:esdi41tofs4toa4efg23567nh0t9mdp47f@4ax.com...
>
>I've converted string representations of Dates into DATE types alot
>before in Windows Apps, I'm just doing the same now in a Web App, I'm
>fairly new to ASP.NET, but the error does not make sense at all:
>
>System.InvalidCastException: Cast from string "14:13:00 21/03/2005" to
>type 'Date' is not valid.
>
>To which I reply "yes it #!$%#% is!!"
>Now, I've seen it before where you try to convert an empty string to a
>date, and of course the poor thing can't convert it, but the above
>looks like a date to me...I'm in the UK so 21 is the day not the
>month. Maybe this is what its refering to, I have the regional
>settings, set to UK style dates, so it should be able to interpret it.
>
>So, whats happening here?
>
>Scott
>
Author
29 Mar 2005 3:07 PM
Cor Ligthert
Ken,

Probably in the UK
> Dim d As DateTime = DateTime.ParseExact("14:13:00 21/03/2005", "HH:mm:ss
> dd/MM/yyyy", New Globalization.CultureInfo("en-UK"))

Typo because the date is correct

:-)

Cor
Author
29 Mar 2005 3:10 PM
Cor Ligthert
Scott,

> System.InvalidCastException: Cast from string "14:13:00 21/03/2005" to
> type 'Date' is not valid.

AFAIK is a standard datetime string in the complete EU "21/03/2005 14:13:00"

Cor
Author
2 Apr 2005 2:37 PM
Scott H
Thanks Cor, I noticed while playing around with Ken's Suggested code
that Some date values had the time first, others had the date first.


On Tue, 29 Mar 2005 17:10:00 +0200, "Cor Ligthert"
<notmyfirstn***@planet.nl> wrote:
Show quoteHide quote
>Scott,
>
>> System.InvalidCastException: Cast from string "14:13:00 21/03/2005" to
>> type 'Date' is not valid.
>
>AFAIK is a standard datetime string in the complete EU "21/03/2005 14:13:00"
>
>Cor
>