To Convert String To Date Format, use the DateTime.ParseExact function
DateTime.ParseExact(s as String, format as String, provider As IFormatProvider) as DateTime
Parameters:
- s
- Type: System.String
A string that contains a date and time to convert.
- format
- Type: System.String
A format specifier that defines the required format of s.
- provider
- Type: System.IFormatProvider
An object that supplies culture-specific format information about s.
Example:
-
Private Function ToDate() As DateTime
-
-
Dim str As String = "20060505"
-
-
Dim mDate As DateTime
-
-
-
-
mDate = DateTime.ParseExact(str, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)
-
-
Return mDate
-
-
End Function
Read More about DateTime.ParseExact Method (String, String, IFormatProvider)