Convert to date

S

simon

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
 
A

Armin Zingler

simon said:
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.
 
H

Herfried K. Wagner [MVP]

* "simon said:
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'?
 
S

simon

I tried with 'DateTime.Parse' and 'DateTime.ParseExact' and still doesn't
work, the same error message.

Thank you,
Simon
 
A

Armin Zingler

simon said:
What you mean? I didn't found founction ConvertToDateTime?

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

Convert.ToDateTime

Dots cost extra. ;-)
 
C

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
 
C

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

Armin Zingler

Cor said:
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.

[/QUOTE]
 
S

simon

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
 
C

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.ToString)
MessageBox.Show(b.ToString)
Dim c As DateTime
MessageBox.Show(c.Now().ToString)

Can you try it also?

Cor
 
P

Phill. W

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

Cor

Hi Herfried,

What does Armin always says about echo?

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

Cor
 
H

Herfried K. Wagner [MVP]

* "Cor said:
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...

;-)
 
A

Armin Zingler

Cor said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top