469,623 Members | 926 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Converting String to A Date

I have a string in this format 100106 what is the most efficient way
to convert it to a date like 10/01/2006 thanks.

Mar 26 '07 #1
5 1831
CType(string, date)

datevar = CDate(string)
Date.Parse or Date.ParseExact

Mar 26 '07 #2
"c_shah" <sh*********@netzero.netschrieb:
>I have a string in this format 100106 what is the most efficient way
to convert it to a date like 10/01/2006 thanks.
Take a look at 'Date.ParseExact'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Mar 26 '07 #3
>
Take a look at 'Date.ParseExact'.

--
I would never advice that especially when I don't know if it has to be 10
januari 2006 or october 1 2006.

The CDate would be the nearest for me as xamman already wrote,

Cor
Mar 27 '07 #4
Cor Ligthert [MVP] wrote:
>Take a look at 'Date.ParseExact'.

--
I would never advice that especially when I don't know if it has to be 10
januari 2006 or october 1 2006.

The CDate would be the nearest for me as xamman already wrote,

Cor
I would never advice that, as the date format clearly needs to be
specified exactly. Just converting it to a date without an exact format
is not likely to produce a usable result, and the result may even vary
depending on culture settings.

With ParseExact you specify exactly how the date format is supposed to
be interpreted. The OP of course knows if the format is "ddMMyy" or
"MMddyy", otherwise parsing the value is impossible.

--
Göran Andersson
_____
http://www.guffa.com
Mar 27 '07 #5
"Cor Ligthert [MVP]" <no************@planet.nlschrieb
>Take a look at 'Date.ParseExact'.

I would never advice that especially when I don't know if it has to be 10
januari 2006 or october 1 2006.
The OP provided a sample and another sample showing how the date should be
parsed. This can be archieved by 'Time.ParseExact' with a fixed format
string, but---as Göran mentions---cannot be archieved using 'CDate'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 27 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Mika M | last post: by
3 posts views Thread by NateM | last post: by
2 posts views Thread by XML newbie: Urgent pls help! | last post: by
9 posts views Thread by Alok yadav | last post: by
3 posts views Thread by zshenk | last post: by
3 posts views Thread by Jef Driesen | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.