I have a datetime that looks like this:
201210120956
ccyyMMDDhhmm
When I try this:
Dim convertedDate As Date = Date.Parse(DateString)
Return convertedDate
I get back this:
#10/12/2012#
I'm losing the time on it.
I've read this convert string to datetime vb.net but when I use datetime.ParseExact()
I get:
cannot resolve symbol 'ParseExact'
Is there a way to convert this to a date time without using substring? A straight conversion?
You can try with ParseExact
method
Sample
Dim format As String
format = "d"
Dim provider As CultureInfo = CultureInfo.InvariantCulture
result = Date.ParseExact(DateString, format, provider)
As an alternative, if you put a space between the date and time, DateTime.Parse
will recognize the format for you. That's about as simple as you can get it. (If ParseExact
was still not being recognized)
Source: Stackoverflow.com