Reputation: 31
On a VB.net website i run a SP that returns a datetime value and i need to pass this value in to a RadTimePicker for display, the format that i get back id the next:
'#5/1/2014 7:05:00 AM.# {Date}
i use the Tostring method and than substring to get only the time
lector("BBIT_01ManEntra").ToString.Substring(10, 12)
that returns the value like this
"7:05:00 a.m."
All of this need to append on the click o a button
Private Sub rbCargar_Click(sender As Object, e As System.EventArgs) Handles rbCargar.Click
lector = objBd.BitacoraGuardada()
While lector.Read
If Not lector("BBIT_01ManEntra") Is DBNull.Value Then rtpEmañana1.SelectedTime = TimeSpan.Parse(lector("BBIT_01ManEntra").ToString.Substring(10, 12))
End While
End Sub
but whe it runs i get this error:
FormatException was unhandled by user code
For this to work i need the time in a 24 hr format not 12 hr can any one help me to make this work or showme a dierent wasy to fet to diapaly the time on the control please
Upvotes: 0
Views: 712
Reputation: 6543
You could use DateTime.Parse to parse the time substring, and ToString to get a 24-hour value:
Dim time = DateTime.Parse("7:05:00 AM")
Dim time24 = time.ToString("HH:mm")
Upvotes: 1
Reputation: 2451
Is lector("BBIT_01ManEntra")
typed as DateTime? If so, we may be able to shorten it and give you a compatible time format with this rtp control you mentioned.
If Not lector("BBIT_01ManEntra") Is DBNull.Value Then rtpEmañana1.SelectedTime = TimeSpan.Parse(lector("BBIT_01ManEntra").ToString("HH:mm"))
Upvotes: 0