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

S

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
 
K

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

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


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
 
C

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
 
C

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
 
S

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top