473,498 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
Nov 21 '05 #1
10 3997
Kiran,

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

Cor
Nov 21 '05 #2
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
Nov 21 '05 #3
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


Nov 21 '05 #4
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
Nov 21 '05 #5
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
Nov 21 '05 #6
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
Nov 21 '05 #7
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

Nov 21 '05 #8
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
Nov 21 '05 #9
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" <ki***@nospam.net> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...
| 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
Nov 21 '05 #10
Jay,

That was probably not a one minute puzzle

However nice. (I remember me this one now)

:-)

Cor
Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
7092
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } ...
11
19564
by: Robert Lacoste | last post by:
Dear Access gurus, I was using since years Access 97, now under XP SP2, without any problem. However I've just reformatted my HD (viruses...), reinstalled XP SP2, and then I am no longer able to...
3
35032
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
175
8638
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
1
1340
by: Kiran | last post by:
Hi, I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) which I get from javascript to date using cdate(string). I get the following error Cast from string "Thu Jul 21 00:00:00...
3
4962
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
4
14774
by: jason.awlt | last post by:
Greetings, I recently being bugged by the following error on my DB2. SQL0902C SQLSTATE = 58005 Reason Code = 14 This error comes out everytime i tried to insert some record to a table...
5
4569
by: Mike | last post by:
Hello All, Please, if anyone can point me to the problem, I'd sure appreciate it! I am very new to VB programming and not a programmer to begin with. This is part of a Visual Basic 2005 Express...
7
4252
by: =?Utf-8?B?U3R1?= | last post by:
I have a ASP.NET Ajax app (using client library) calling ASP.NET Ajax-enabled web services. We are making use of the javascript proxies generated by ASP.NET Ajax. The problem we have is that the...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4904
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.