469,929 Members | 1,459 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

Convert to date

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
19 8456
* "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
"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
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
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
"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
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
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
"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
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
"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
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
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
"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
* "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
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
* "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
"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
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
* "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.

Similar topics

19 posts views Thread by Lauren Quantrell | last post: by
4 posts views Thread by Richard Hollenbeck | last post: by
3 posts views Thread by jerry.ranch | last post: by
2 posts views Thread by Franck | last post: by
17 posts views Thread by Terry Jolly | last post: by
4 posts views Thread by perryclisbee via AccessMonster.com | last post: by
8 posts views Thread by deepak_kamath_n | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.