Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting "123105" to a date..

Status
Not open for further replies.

VladimirKim

Programmer
Jan 20, 2005
49
0
0
US
Hi.
Is there a function in VB.NET to convert a string, let's say "123105", to a date "12/31/05"?
Thanks.
 
Use the .insert of the string and add two "/".

dim strDate as string = "123105"
strDate = strDate.Insert( ... ).insert( ... )

Use two inserts like the example of the two "/"

Then : dim tDate as date = CDate(strDate)
 
Dim strDate As String = "311205"
strDate = strDate.Insert(2, "/").Insert(5, "/")
Dim tDate As Date = CDate(strDate)
MsgBox(tDate)

Notice that i changed "123105" to "311205" because there will be an exception. The reason: 12=day, 31=month??, 05=year. For you it will be ok.

So you have before converting it to date to apply to the string a format like: "mm/dd/yy" for example


Hope these help
 
I think CDate("123105").ToString also works.

Have a great day!

j2consulting@yahoo.com
 
A slight modification/extension to Rick's solution:

CDate(CInt("123105").ToString("##/##/##")).ToString("MM/dd/yy")

Hope this helps.
 
Thanks a lot to all of you. that's exactly what i needed.
Vladimir
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top