Dear all,
I have the following:
dim tmpString as String = "11/21/2004 07:55:33"
dim tmpDate as Date = CDate(tmpString)
But I keep getting <cast from string "11/21/2004 07:55:33" to type 'Date' is
not valid.> Is there anything that I did wrong?
Thanks.
--Simon 22 4091
Hi,
Dim tmpString As String = "11/21/2004 07:55:33"
Dim tmpDate As Date = DateTime.Parse(tmpString)
Ken
---------------
"Simon Says" <te*******@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...
Dear all,
I have the following:
dim tmpString as String = "11/21/2004 07:55:33"
dim tmpDate as Date = CDate(tmpString)
But I keep getting <cast from string "11/21/2004 07:55:33" to type 'Date' is
not valid.> Is there anything that I did wrong?
Thanks.
--Simon
Simon,
For non USA timezone using visitors to this newsgroup.
\\\
Dim mydate As String = _
New Date(2004, 11, 21, 7, 55, 33).toString
tmpDate = CDate(mydate)
///
I hope this helps?
Cor
"Simon Says" <te*******@hotmail.com> I have the following:
dim tmpString as String = "11/21/2004 07:55:33" dim tmpDate as Date = CDate(tmpString)
But I keep getting <cast from string "11/21/2004 07:55:33" to type 'Date' is not valid.> Is there anything that I did wrong?
Thanks.
--Simon
"Simon Says" <te*******@hotmail.com> schrieb: I have the following:
dim tmpString as String = "11/21/2004 07:55:33" dim tmpDate as Date = CDate(tmpString)
But I keep getting <cast from string "11/21/2004 07:55:33" to type 'Date' is not valid.> Is there anything that I did wrong?
Use 'DateTime.Parse' or 'DateTime.ParseExact' and specify an appropriate
'CultureInfo' object. If you don't know the culture of the date format, use
'CultureInfo.InvariantCulture' + an explicit date/time format string in
'DateTime.ParseExact'.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
The OP wanted to know how to go from a string to a date. You show how to go
from a date to a string to a date. If he had the date in the first place
would he need to ask his question? Does that make sense?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl... Simon,
For non USA timezone using visitors to this newsgroup.
\\\ Dim mydate As String = _ New Date(2004, 11, 21, 7, 55, 33).toString tmpDate = CDate(mydate) ///
I hope this helps?
Cor
"Simon Says" <te*******@hotmail.com> I have the following:
dim tmpString as String = "11/21/2004 07:55:33" dim tmpDate as Date = CDate(tmpString)
But I keep getting <cast from string "11/21/2004 07:55:33" to type
'Date' is not valid.> Is there anything that I did wrong?
Thanks.
--Simon
JD, The OP wanted to know how to go from a string to a date. You show how to go from a date to a string to a date. If he had the date in the first place would he need to ask his question? Does that make sense?
Do you mean he wants to hard code in this way a date in his program. I
assume you don't do it that way and I assume the OP does not do that either.
In my opinion his datestring can come from a document or a textbox or
whatever and is he just giving it as an example.
Therefore I show a sample that works in every culture.
Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eE***************@TK2MSFTNGP10.phx.gbl... JD,
The OP wanted to know how to go from a string to a date. You show how to go from a date to a string to a date. If he had the date in the first place would he need to ask his question? Does that make sense? Do you mean he wants to hard code in this way a date in his program. I assume you don't do it that way and I assume the OP does not do that
either. In my opinion his datestring can come from a document or a textbox or whatever and is he just giving it as an example.
Exactly. The OP starts off with a *string* that can come from anywhere. So
how does your example help him when in your example you start off with a
*date* not a *string*?
>> > The OP wanted to know how to go from a string to a date. You show how > to > go > from a date to a string to a date. If he had the date in the first > place > would he need to ask his question? Does that make sense? > Do you mean he wants to hard code in this way a date in his program. I assume you don't do it that way and I assume the OP does not do that
either. In my opinion his datestring can come from a document or a textbox or whatever and is he just giving it as an example.
Exactly. The OP starts off with a *string* that can come from anywhere. So how does your example help him when in your example you start off with a *date* not a *string*?
JD
Why do you think that you understand that in the sample that string is first
made and the OP does not?
Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl... > The OP wanted to know how to go from a string to a date. You show how > to > go > from a date to a string to a date. If he had the date in the first > place > would he need to ask his question? Does that make sense? > Do you mean he wants to hard code in this way a date in his program. I assume you don't do it that way and I assume the OP does not do that either. In my opinion his datestring can come from a document or a textbox or whatever and is he just giving it as an example.
Exactly. The OP starts off with a *string* that can come from anywhere.
So how does your example help him when in your example you start off with a *date* not a *string*? JD
Why do you think that you understand that in the sample that string is
first made and the OP does not?
Because the OP is asking how to convert a *string* to *date*. Why do you
think he has a date first?
"JD" <no@address.org> schreef in bericht
news:Oj**************@tk2msftngp13.phx.gbl... "Cor Ligthert" <no************@planet.nl> wrote in message news:Of**************@TK2MSFTNGP11.phx.gbl... >> > The OP wanted to know how to go from a string to a date. You show >> > how >> > to >> > go >> > from a date to a string to a date. If he had the date in the first >> > place >> > would he need to ask his question? Does that make sense? >> > >> Do you mean he wants to hard code in this way a date in his program. I >> assume you don't do it that way and I assume the OP does not do that > either. >> >> In my opinion his datestring can come from a document or a textbox or >> whatever and is he just giving it as an example. > > Exactly. The OP starts off with a *string* that can come from anywhere. So > how does your example help him when in your example you start off with > a > *date* not a *string*? > JD
Why do you think that you understand that in the sample that string is
first made and the OP does not?
Because the OP is asking how to convert a *string* to *date*. Why do you think he has a date first?
Can you give the exact answer for that.
By instance for the string "JD"
Cor
I have absolutely no clue what you are talking about...
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl... "JD" <no@address.org> schreef in bericht news:Oj**************@tk2msftngp13.phx.gbl... "Cor Ligthert" <no************@planet.nl> wrote in message news:Of**************@TK2MSFTNGP11.phx.gbl... >> > The OP wanted to know how to go from a string to a date. You show >> > how >> > to >> > go >> > from a date to a string to a date. If he had the date in the first >> > place >> > would he need to ask his question? Does that make sense? >> > >> Do you mean he wants to hard code in this way a date in his program.
I >> assume you don't do it that way and I assume the OP does not do that > either. >> >> In my opinion his datestring can come from a document or a textbox
or >> whatever and is he just giving it as an example. > > Exactly. The OP starts off with a *string* that can come from
anywhere. So > how does your example help him when in your example you start off
with > a > *date* not a *string*? > JD
Why do you think that you understand that in the sample that string is first made and the OP does not?
Because the OP is asking how to convert a *string* to *date*. Why do you think he has a date first?
Can you give the exact answer for that. By instance for the string "JD"
Cor
I have absolutely no clue what you are talking about...
Strange you are all the time answering in line, and now you do not know when
I am talking about when I ask this accoording to your message > Because the OP is asking how to convert a *string* to *date*. Why do > you > think he has a date first? > Can you give the exact answer for that. By instance for the string "JD"
Show me how you convert the "string" "JD" to a "date".
Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... I have absolutely no clue what you are talking about... Strange you are all the time answering in line, and now you do not know
when I am talking about when I ask this accoording to your message > Because the OP is asking how to convert a *string* to *date*. Why do > you > think he has a date first? > Can you give the exact answer for that. By instance for the string "JD"
Show me how you convert the "string" "JD" to a "date".
Why? Show me how you convert the "string" "JD" to a "date".
Why?
Because you are telling that, that is the question and my answer is not
right.
Or can you only tell other people what is wrong?
Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl... Show me how you convert the "string" "JD" to a "date".
Why?
Because you are telling that, that is the question and my answer is not right.
Or can you only tell other people what is wrong?
Cor
No I'm not. I think you are confused.
"JD" <no@address.org> schreef in bericht
news:OJ*************@TK2MSFTNGP12.phx.gbl... "Cor Ligthert" <no************@planet.nl> wrote in message news:OO**************@TK2MSFTNGP10.phx.gbl... >> Show me how you convert the "string" "JD" to a "date". > > Why? > Because you are telling that, that is the question and my answer is not right.
Or can you only tell other people what is wrong?
Cor
No I'm not. I think you are confused.
You mean you did not write that bellow, are there more JD's or is it you who
is confused?
Exactly. The OP starts off with a *string* that can come from anywhere. So
how does your example help him when in your example you start off with a
*date* not a *string*?
Show me starting with a string with the value "JD" how you convert that to a
datetime.
Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl... "JD" <no@address.org> schreef in bericht news:OJ*************@TK2MSFTNGP12.phx.gbl... "Cor Ligthert" <no************@planet.nl> wrote in message news:OO**************@TK2MSFTNGP10.phx.gbl... >> Show me how you convert the "string" "JD" to a "date". > > Why? > Because you are telling that, that is the question and my answer is not right.
Or can you only tell other people what is wrong?
Cor
No I'm not. I think you are confused.
You mean you did not write that bellow, are there more JD's or is it you
who is confused?
Exactly. The OP starts off with a *string* that can come from anywhere. So how does your example help him when in your example you start off with a *date* not a *string*?
Show me starting with a string with the value "JD" how you convert that to
a datetime.
Cor
Thats called *validation*, the OP was not trying to *validate* the string,
he was trying to *convert* the date string.
JD,
Maybe you still don't understand it, however in my culture as in a lot of
others is the string he showed the same invalid as "JD" Thats called *validation*, the OP was not trying to *validate* the string, he was trying to *convert* the date string.
And because there are not only visitors from the US here, I showed it in a
way that it would work in all cultures. This newsgroup is used for reference
as well.
Maybe you find it rude, however I don't add anything more to this thread.
Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oz*************@TK2MSFTNGP12.phx.gbl... JD,
Maybe you still don't understand it, however in my culture as in a lot of others is the string he showed the same invalid as "JD"
Thats called *validation*, the OP was not trying to *validate* the
string, he was trying to *convert* the date string. And because there are not only visitors from the US here, I showed it in a way that it would work in all cultures. This newsgroup is used for
reference as well.
I perfectly understand the culture differences but you are clearly still
confused. The question at hand was "how to convert a string, in a specific
culture format, to a date". Herfried's reply was correct. Your example
showed "how to convert a date to a string, back to a date again", which
really doesn't make sense when you can recieve date strings from around the
world through web services, files, etc., all with different formats.
"Cor Ligthert" <no************@planet.nl> schrieb: And because there are not only visitors from the US here, I showed it in a way that it would work in all cultures. This newsgroup is used for reference as well.
How would it work if the string is read from a file?
Your sample doesn't show how to convert a date string in a certain
(uninfluencable) format to a 'Date'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Your samples do not work on standard Austrian computers.
Cor Herfried's reply was correct.
Herfried???????????????
Cor
:- )
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Herfried's reply was correct.
Herfried???????????????
Cor
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
When I execute the following (with an OleDBDataAdapter),
wanting to add a row to a visual foxpro table:
myrow= datasetTarget.Tables(0).NewRow
'fill all columns here like..
row(i)= myvalue
'...
|
by: Krung Saengpole |
last post by:
Hi,
I used SQL Server 2000 Personal Edition. I created a stored procedure
having input parameters as smallint,tinyint,char,varchar and
smalldatetime. When I executed it by Query Analyzer, it's...
|
by: Nick Flandry |
last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my
development environment (Win2K server running IIS 5) and a test environment (also Win2K server
running IIS...
|
by: adams114 |
last post by:
I am having a strange problem with invalid type casts. I am trying to
update a MS SQL Database with a stored procedure. When I setup the
parameters collection for the command object I get a invalid...
|
by: John Howard |
last post by:
Making the following call to a local MSAccess database works fine:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim intRows As Integer
Dim strSQL As String
Dim ds As New...
|
by: Hifni Shahzard |
last post by:
Hi,
I got a stored procedure, where it returns a value. But if I execute it. It
gives an error as "Invalid cast from System.Int32 to System.Byte.". To make
clear how do I execute this, below I'm...
|
by: gavin |
last post by:
Have a Windows for with a textbox.
Enter a date 2006/1/1/ -Note an additinal / on th end
This is clearly an error but when text is cast to a date the extra / is
automatically removed. The cast...
|
by: syntego |
last post by:
We commonly use triggers to log changes to our main tables to
historical log tables.
In the trigger, we create a concatenated string of the old values by
casting them as follows:
...
|
by: chance |
last post by:
Getting and error on this first line of code:
//inspector phone
theField = reader.GetString(20);
builder.MoveToBookmark("inspector_phone");
builder.Write(theField);
the first line is...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |