471,863 Members | 979 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

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 1900
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
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.