vb.net convert 24 hour to 12 hour

trying to figure out how to convert a record stored as 24 hour in db to 12 hour when displayed in my program.   Among other things I have tried the following code:

Dim strTime As String = String.Format("{0:hh:mm tt}", CloseTime)

Open in new window


This still gives 24 hour time.   Any help is appreciated.
McGurk1Asked:
Who is Participating?
 
lluddenConnect With a Mentor Commented:
Cast it as a date and try it.

Dim strTime As String = String.Format("{0:hh:mm tt}", CDate(CloseTime))
0
 
McGurk1Author Commented:
have also tried:

strTime = CloseTime.ToString("hh:mm AMPM")

Open in new window

0
 
lluddenCommented:
What is the datatype of Closetime?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
McGurk1Author Commented:
datatype is time(7)
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Try:
Dim strTime As String = String.Format("{0:h:mm tt}", CloseTime)

Or this:
Dim strTime As String = Convert.ToDateTime(CloseTime).ToString("h:mm tt");
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Or this too:
Dim strTime As String = CloseTime.ToString("h:mm tt");
0
 
McGurk1Author Commented:
Thanks for all of the help.  Tried all of the suggestions.  lludden's worked when I cast it to a date first..

my final code:
Dim dtTime as Date = CDate(CloseTime)
Dim strTime as String = String.Format("{0:h:mm tt}", dtTime)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.