I'm looking for a way to convert a 5 character time representation to a date object. ie. "0937a" should be "6/16/2010 9:37 AM" or "1215p" should be "6/16/2010 12:15 PM". Thanks for any help...
Printable View
I'm looking for a way to convert a 5 character time representation to a date object. ie. "0937a" should be "6/16/2010 9:37 AM" or "1215p" should be "6/16/2010 12:15 PM". Thanks for any help...
I don't have access to vb.net at the moment so here is something from vb6 which you can amend as per your requirement and convert to vb.net :)
Code:Sub Sample()
Dim strTime As String
strTime = "0937a"
strTime = Mid(strTime, 1, 2) & ":" & Mid(strTime, 3)
If Right(strTime, 1) = "a" Then
strTime = Replace(strTime, "a", " AM")
ElseIf Right(strTime, 1) = "p" Then
strTime = Replace(strTime, "p", " PM")
End If
MsgBox Date & " " & strTime
End Sub
vb.net Code:
Private Function GetDate(ByVal time As String) As Date Return Date.Today + Date.ParseExact(time & "m", "hhmmtt", Nothing).TimeOfDay End Function