Converting a String to a Date in VB.Net

G

Guest

Hi,

This seems quite simple but I don't know what I am doing wrong.

I have a string as "15122004"

I want to convert this to a date.

I have Option Strict On.

How can I convert this string to a date in format ("dd/mm/yyyy") without
turning off Option Strict?

Thanks.
 
H

Hans Kesting

CG said:
Hi,

This seems quite simple but I don't know what I am doing wrong.

I have a string as "15122004"

I want to convert this to a date.

I have Option Strict On.

How can I convert this string to a date in format ("dd/mm/yyyy")
without turning off Option Strict?

Thanks.

in C# syntax, but this should be easily convertible:

string myDateString = "15122004";
DateTimeFormatInfo myDTFI = new DateTimeFormatInfo();
myDTFI.ShortDatePattern = "ddMMyyyy";
DateTime dt = DateTime.Parse(myDateString, myDTFI);

Hans Kesting
 
Joined
Dec 18, 2007
Messages
2
Reaction score
0
Dim strDate As String
Dim objdate As Date
strDate = "11301982"
strDate = strDate.Substring(0, 2) & "/" & strDate.Substring(2, 2) & "/" & strDate.Substring(4, 4)
objdate = Date.Parse(strDate).ToShortDateString
lbl_Test.Text = objdate

:driver:
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,147
Latest member
CarenSchni
Top