I have a string
that looks like "17th December 2012" and I want to convert it to a datetime
, with a format of dd/MM/yyyy.
I have been on this link but that is the opposite of what I want to achieve.
I can do it by removing the suffix ("th" in "17th") by doing substrings and such and then converting it to datetime
, but is there a direct way of achieving this?
a C# code would also do.
This is my code as of now, but it looks so ugly.. lol.
Private Function gettime(ByVal thetime As String) As DateTime
Dim result As DateTime
Dim str1 As String = thetime
Dim str2 As String = str1
Dim ind As Integer = 0
ind = str1.IndexOf(" ")
str2 = str1.Substring(0, ind)
str2 = Trim(StrReverse(str2))
str2 = str2.Substring(2, 2)
str2 = StrReverse(str2)
ind = str1.IndexOf(" ")
str1 = str2 & str1.Substring(ind)
result = DateTime.Parse(str1)
Return result
End Function