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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert string to date 2

Status
Not open for further replies.

DerPflug

Programmer
Mar 28, 2002
153
0
0
US
How can I convert a string from "08102004" to "08/10/2004")?
 
You could do this if you wanted it to use the same variable.

Dim str As String = "08102004"
str = str.Insert(2, "/").Insert(5, "/")
 
PankajBanga,

Your Solution is great! However, if one wanted to make 08 the month instead of 10, the following slight modification accomplishes it.

Dim str As String = "08102004"

Dim dt As Date = New Date(str.Substring(4), str.Substring(0, 2), str.Substring(2, 2))

MessageBox.Show(dt)

Both solutions work well (ca8spo), depending on your needs. Stars to all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top