We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

vb.net convert 24 hour to 12 hour

McGurk1
McGurk1 asked
on
Medium Priority
1,611 Views
Last Modified: 2012-05-11
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.
Comment
Watch Question

Author

Commented:
have also tried:

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

Open in new window

CERTIFIED EXPERT

Commented:
What is the datatype of Closetime?

Author

Commented:
datatype is time(7)
Carlos VillegasFull Stack .NET Developer

Commented:
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");
Carlos VillegasFull Stack .NET Developer

Commented:
Or this too:
Dim strTime As String = CloseTime.ToString("h:mm tt");
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.