PC Review


Reply
Thread Tools Rate Thread

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

 
 
Kiran
Guest
Posts: n/a
 
      4th Aug 2005
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
 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      4th Aug 2005
Kiran,

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

Cor


 
Reply With Quote
 
Kiran
Guest
Posts: n/a
 
      4th Aug 2005
Cor Ligthert [MVP] wrote:
> 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
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      4th Aug 2005
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




 
Reply With Quote
 
Kiran
Guest
Posts: n/a
 
      4th Aug 2005
Cor Ligthert [MVP] wrote:
> 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
>
>
>
>


Hi Cor

The culture is "en-GB"

Thanks
Kiran
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      4th Aug 2005
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.
>>

>
> 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


 
Reply With Quote
 
Kiran
Guest
Posts: n/a
 
      4th Aug 2005
Cor Ligthert [MVP] wrote:
> 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.
>>>

>>
>>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
>
>

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
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      4th Aug 2005

> 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



 
Reply With Quote
 
Kiran
Guest
Posts: n/a
 
      4th Aug 2005
Cor Ligthert [MVP] wrote:
>>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
>
>
>

Thanks Cor, I got it working.

I translated the date in client side.

Thanks
Kiran
 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      4th Aug 2005
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/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay

Hope this helps
Jay

"Kiran" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cast from string "" to type 'Date' is not valid zafzal@gmail.com Microsoft VB .NET 2 8th Feb 2006 07:17 PM
Cast from string "" to type 'Date' is not valid zafzal@gmail.com Microsoft ASP .NET 2 3rd Feb 2006 11:36 AM
Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date'is not valid(System.InvalidCastException) Kiran Microsoft ASP .NET 1 4th Aug 2005 11:01 AM
InvalidCastException "Cast from string "6<5" to type 'Boolean is not valid. hazz Microsoft VB .NET 3 7th Jul 2005 10:22 PM
"System.InvalidCastException: Specified cast is not valid." during connection.open Roy Lawson Microsoft ASP .NET 12 25th Oct 2004 06:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:35 AM.