SOLUTION
Thanks to casper, here is my resulting function:
Shared Function FormatDate(ByVal s As String) As String
Dim DT As DateTime
s = Regex.Replace(s, "[^1234567890]", "")
DT = DateTime.ParseExact(s, "HHmm", Globalization.CultureInfo.InvariantCulture)
Return DT.ToString("h:mm tt")
End Function
Much better :D
I am reading a database that holds time information in a string format, hh:mm. For some reason I am remembering a built-in function I used a long time ago to accomplish, but for the life of me I cannot remember how to do it. So instead, I wrote this quick n dirty function:
Shared Function FormatDate(ByVal s As String) As String
'' this function takes a time string from the database
'' and changes it from 24h to 12h
Dim oSplit As String() = s.Split(":"c)
Dim oRet As String = "", suffix As String = ""
Dim hour, minute As String
If CInt(oSplit(0)) > 12 Then
hour = CStr(CInt(oSplit(0)) - 12)
suffix = "PM"
Else
hour = oSplit(0)
suffix = "AM"
End If
minute = oSplit(1)
oRet = String.Format("{0}:{1} {2}", hour, minute, suffix)
Return oRet
End Function
Does anyone know of the particular function I am think I am referring to?
Thanks!