Use custom formats with M and MM to parse a string to Date
Imports System.Globalization
Class MainClass
Public Shared Sub Main()
Dim enUS As New CultureInfo("en-US")
Dim dateString As String
Dim dateValue As Date
dateString = "5/01/2009 09:00"
Try
dateValue = Date.ParseExact(dateString, "M/dd/yyyy hh:mm", enUS, DateTimeStyles.None)
Console.WriteLine(dateValue)
Catch e As FormatException
Console.WriteLine("'{0}' is not in an acceptable format.", dateString)
End Try
End Sub
End Class
Related examples in the same category