By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

Convert to date

P: n/a
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM"

Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error message:
String was not recognized as a valid DateTime.

What should I do?
Use replace function and mid function on string and at the end convert it to date?

Thank you for your answer,
Simon
Nov 20 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
* "simon" <si*********@stud-moderna.si> scripsit:
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM"

Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error message:

String was not recognized as a valid DateTime.


Did you try it with 'DateTime.Parse' or 'DateTime.ParseExact'?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
"simon" <si*********@stud-moderna.si> schrieb
I get from the dateTimePicker the value: string="12/18/2003 11:52:28
AM"

Now I need to convert this to dateTime. Any function I use:
Convert.ToDateTime(string) or Cdate(string), I get an error message:
String was not recognized as a valid DateTime.

What should I do?
Use replace function and mid function on string and at the end
convert it to date?


You're from Slovenia? Do you have the English date/time format? Here in
Germany it is dd.mm.yyyy hh:mm:ss, so ConvertToDateTime("18.12.2003
11:52.28") works.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3

P: n/a
I tried with 'DateTime.Parse' and 'DateTime.ParseExact' and still doesn't
work, the same error message.

Thank you,
Simon

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:br************@ID-208219.news.uni-berlin.de...
* "simon" <si*********@stud-moderna.si> scripsit:
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM"

Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error message:
String was not recognized as a valid DateTime.


Did you try it with 'DateTime.Parse' or 'DateTime.ParseExact'?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4

P: n/a
What you mean? I didn't found founction ConvertToDateTime?
Thank you,
Simon

"Armin Zingler" <az*******@freenet.de> wrote in message
news:e$**************@TK2MSFTNGP09.phx.gbl...
"simon" <si*********@stud-moderna.si> schrieb
I get from the dateTimePicker the value: string="12/18/2003 11:52:28
AM"

Now I need to convert this to dateTime. Any function I use:
Convert.ToDateTime(string) or Cdate(string), I get an error message:
String was not recognized as a valid DateTime.

What should I do?
Use replace function and mid function on string and at the end
convert it to date?


You're from Slovenia? Do you have the English date/time format? Here in
Germany it is dd.mm.yyyy hh:mm:ss, so ConvertToDateTime("18.12.2003
11:52.28") works.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

P: n/a
"simon" <si*********@stud-moderna.si> schrieb
What you mean? I didn't found founction ConvertToDateTime?


A little bit more creativity, please! ;-) Fun only...

Convert.ToDateTime

Dots cost extra. ;-)
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6

P: n/a
Cor
Hi Simon,

I am also from Europe

Dim b As New DateTime
b = Convert.ToDateTime("18/12/2003 11:52:28 AM")
MessageBox.Show(b.ToString)

Works for my

Cor

Nov 20 '05 #7

P: n/a
Cor
Hi Armin,

Germany it is dd.mm.yyyy hh:mm:ss, so ConvertToDateTime("18.12.2003
11:52.28") works.


Really?

:-)))

Cor
Nov 20 '05 #8

P: n/a
"Cor" <no*@non.com> schrieb
Germany it is dd.mm.yyyy hh:mm:ss, so
ConvertToDateTime("18.12.2003 11:52.28") works.


Really?

:-)))

Yes, really:
Private Function ConvertToDateTime(ByVal s As String) As Date
Return Convert.ToDateTime(s)
End Function
;-))

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9

P: n/a
Cor
Hi Armin,

Look again, you know that I would not send it like this if there was not
something with it that was something absolute not important.
Germany it is dd.mm.yyyy hh:mm:ss, so
ConvertToDateTime("18.12.2003 11:52.28") works.

------
Really?

:-)))

Nov 20 '05 #10

P: n/a
"Cor" <no*@non.com> schrieb
Hi Armin,

Look again, you know that I would not send it like this if there was
not something with it that was something absolute not important.


I thought you referred to the wrong function name.
--
Armin

> Germany it is dd.mm.yyyy hh:mm:ss, so
> ConvertToDateTime("18.12.2003 11:52.28") works.

------
Really?

:-)))

Nov 20 '05 #11

P: n/a
I read a value from timePicker and it is:

start="12/18/2003 11:52:28 AM" String

If I watch function now:

dim dt as DateTime
dt=Now() I get:
dt=#12/19/2003 9:09:19 AM# Date
so I guess this is my system dateTime format.

Then if I use:
dt = Convert.ToDateTime(start)

I still get an error message:
String was not recognized as a valid DateTime.

I don't know what else should I do?

Thank you,
Simon
"Cor" <no*@non.com> wrote in message
news:e#**************@TK2MSFTNGP10.phx.gbl...
Hi Simon,

I am also from Europe

Dim b As New DateTime
b = Convert.ToDateTime("18/12/2003 11:52:28 AM")
MessageBox.Show(b.ToString)

Works for my

Cor

Nov 20 '05 #12

P: n/a
Cor
Hi Simon,

When I try this I get 3 times the date from now
MessageBox.Show(Me.DateTimePicker1.Value.ToString)
Dim b As New DateTime
b = Convert.ToDateTime(Me.DateTimePicker1.Value.ToStri ng)
MessageBox.Show(b.ToString)
Dim c As DateTime
MessageBox.Show(c.Now().ToString)

Can you try it also?

Cor

I read a value from timePicker and it is:

start="12/18/2003 11:52:28 AM" String

If I watch function now:

dim dt as DateTime
dt=Now() I get:
dt=#12/19/2003 9:09:19 AM# Date
so I guess this is my system dateTime format.

Then if I use:
dt = Convert.ToDateTime(start)

I still get an error message:
String was not recognized as a valid DateTime.

I don't know what else should I do?

Thank you,
Simon
"Cor" <no*@non.com> wrote in message
news:e#**************@TK2MSFTNGP10.phx.gbl...
Hi Simon,

I am also from Europe

Dim b As New DateTime
b = Convert.ToDateTime("18/12/2003 11:52:28 AM")
MessageBox.Show(b.ToString)

Works for my

Cor


Nov 20 '05 #13

P: n/a
"simon" <si*********@stud-moderna.si> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...

OK, I'm new around here but...
I get from the dateTimePicker the value:
string="12/18/2003 11:52:28 AM" .. . . Now I need to convert this to dateTime.


No, you don't.
The DateTimePicker's Value property is /already/ of Type
DateTime (not String), so you should be able to use the value
directly, without any conversion at all.

Air-Code (finger's crossed)

Dim SomeTimeSoon as New DateTime
SomeTimeSoon = DateTimePicker1.Value
MessageBox.Show( SomeTimeSoon.ToString() )

HTH,
Phill W.
Nov 20 '05 #14

P: n/a
* "simon" <si*********@stud-moderna.si> scripsit:
I read a value from timePicker and it is:

start="12/18/2003 11:52:28 AM" String


Why not use the 'Value' directly?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #15

P: n/a
Cor
Hi Herfried,

What does Armin always says about echo?

I did give him the change to find that himself with my example.

Cor

Why not use the 'Value' directly?

Nov 20 '05 #16

P: n/a
* "Cor" <no*@non.com> scripsit:
What does Armin always says about echo?

I did give him the change to find that himself with my example.


LOL... I made it easier for the OP...

;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #17

P: n/a
"Cor" <no*@non.com> schrieb
Hi Herfried,

What does Armin always says about echo?

I did give him the change to find that himself with my example.


??
Sorry, I don't understand you again.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #18

P: n/a
Cor
Hi Armin,
What does Armin always says about echo?

I did give him the change to find that himself with my example.


??
Sorry, I don't understand you again.


Intruiging, but Herfried does, it is not important that you do understand
this.

Cor
Nov 20 '05 #19

P: n/a
* "Cor" <no*@non.com> scripsit:
What does Armin always says about echo?

I did give him the change to find that himself with my example.


??
Sorry, I don't understand you again.


Intruiging, but Herfried does, it is not important that you do understand
this.


LOL

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.