Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.InvalidCastExc

K

Kiran

Hi,

I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) to
date. I get the following error

Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is
not valid(System.InvalidCastException)

Any help on this will be appreciated

Thanks
Kiran
 
C

Cor Ligthert [MVP]

Kiran,

Is the string format "Thu Jul 21 00:00:00 UTC+0100 200" a valid date in your
culture and calendersettings?

Cor
 
K

Kiran

Cor said:
Kiran,

Is the string format "Thu Jul 21 00:00:00 UTC+0100 200" a valid date in your
culture and calendersettings?

Cor
Hi Cor,

yes it is a valid date and I am getting the value from javascript and
this is the value I get from clientside.

"Thu Jul 21 00:00:00 UTC+0100 2005"

Thanks
Kiran
 
C

Cor Ligthert [MVP]

Kiran,
yes it is a valid date and I am getting the value from javascript and this
is the value I get from clientside.

"Thu Jul 21 00:00:00 UTC+0100 2005"
Can you tell what culture this is in?

Otherwise it is impossible to simulate it.

Cor
 
C

Cor Ligthert [MVP]

Kiran,
The culture is "en-GB"
Kiran,

I can be terrible wrong, however this is maybe a valid date, however not in
the context from how a datetime has to be in a string in the culture en-GB
to be valid to cast.

One of those is
04/08/05 for today

Maybe some persons from that culture, which I know are active here, can give
some samples of those.

I hope this helps

Cor
 
K

Kiran

Cor said:
Kiran,



Kiran,

I can be terrible wrong, however this is maybe a valid date, however not in
the context from how a datetime has to be in a string in the culture en-GB
to be valid to cast.

One of those is
04/08/05 for today

Maybe some persons from that culture, which I know are active here, can give
some samples of those.

I hope this helps

Cor
Hi Cor,

you got me wrong, I get this value from clientside(from a ultrawebgrid
control).

On the server side I want to convert this value to date so that I can
use it.

Thanks
kiran
 
C

Cor Ligthert [MVP]

you got me wrong, I get this value from clientside(from a ultrawebgrid
control).

On the server side I want to convert this value to date so that I can use
it.

Therefore you have first to translate it (as what I assume this is not a
valid en-GB format) to a string that is in a valid format to make it able to
be used in CDate, parse or convert.

You have all the ingredients, so when it would have to be
21/07/2005 you can use something as Regex to do that

RegexLib
http://www.regexlib.com/Default.aspx

Expresso
http://www.ultrapico.com/Expresso.htm

I hope this helps a little bit?

Cor
 
K

Kiran

Cor said:
Therefore you have first to translate it (as what I assume this is not a
valid en-GB format) to a string that is in a valid format to make it able to
be used in CDate, parse or convert.

You have all the ingredients, so when it would have to be
21/07/2005 you can use something as Regex to do that

RegexLib
http://www.regexlib.com/Default.aspx

Expresso
http://www.ultrapico.com/Expresso.htm

I hope this helps a little bit?

Cor
Thanks Cor, I got it working.

I translated the date in client side.

Thanks
Kiran
 
J

Jay B. Harlow [MVP - Outlook]

Kiran,
Are you using CDate or DateTime.ParseExact. It sounds like you are using
CDate, when you should be using DateTime.ParseExact. Something like:

Dim input As String = "Thu Jul 21 00:00:00 UTC+0100 2005"

Const format As String = "ddd MMM dd hh:mm:ss \U\T\Czzzz yyyy"
Dim value As DateTime = DateTime.ParseExact(input, _
format, System.Globalization.CultureInfo.InvariantCulture)

For details on custom datetime formats see:

http://msdn.microsoft.com/library/d...s/cpguide/html/cpcondatetimeformatstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp

Hope this helps
Jay

Hope this helps
Jay

| Hi,
|
| I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) to
| date. I get the following error
|
| Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is
| not valid(System.InvalidCastException)
|
| Any help on this will be appreciated
|
| Thanks
| Kiran
 
C

Cor Ligthert [MVP]

Jay,

That was probably not a one minute puzzle

However nice. (I remember me this one now)

:)

Cor
 

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